Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6fe5202a
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6fe5202a
编写于
2月 26, 2021
作者:
sangshuduo
提交者:
GitHub
2月 26, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5275 from taosdata/feature/TD-2868
Feature/td 2868
上级
f4399816
2b165d84
变更
32
展开全部
隐藏空白更改
内联
并排
Showing
32 changed file
with
1948 addition
and
587 deletion
+1948
-587
cmake/install.inc
cmake/install.inc
+1
-1
src/connector/jdbc/CMakeLists.txt
src/connector/jdbc/CMakeLists.txt
+1
-1
src/connector/jdbc/deploy-pom.xml
src/connector/jdbc/deploy-pom.xml
+1
-1
src/connector/jdbc/pom.xml
src/connector/jdbc/pom.xml
+1
-26
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java
...c/src/main/java/com/taosdata/jdbc/AbstractConnection.java
+7
-6
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java
...bc/src/main/java/com/taosdata/jdbc/AbstractStatement.java
+93
-16
src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
...ain/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
+68
-68
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
...ector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
+29
-31
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
+16
-12
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+3
-5
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
...rc/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+205
-48
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+3
-42
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
...src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
+6
-5
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java
...dbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java
+12
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulPreparedStatement.java
...n/java/com/taosdata/jdbc/rs/RestfulPreparedStatement.java
+465
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
.../src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
+22
-23
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
.../src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
+26
-26
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java
...main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java
+8
-15
src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java
...rc/test/java/com/taosdata/jdbc/PreparedStatementTest.java
+0
-184
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
...est/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
+117
-61
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
...bc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
+182
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java
...ava/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java
+2
-2
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java
...dbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java
+1
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java
...rc/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java
+1
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java
...test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java
+1
-4
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java
...va/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java
+246
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulStatementTest.java
.../test/java/com/taosdata/jdbc/rs/RestfulStatementTest.java
+418
-0
tests/examples/JDBC/JDBCDemo/pom.xml
tests/examples/JDBC/JDBCDemo/pom.xml
+1
-1
tests/examples/JDBC/taosdemo/pom.xml
tests/examples/JDBC/taosdemo/pom.xml
+1
-1
tests/examples/JDBC/taosdemo/readme.md
tests/examples/JDBC/taosdemo/readme.md
+8
-1
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
.../main/java/com/taosdata/taosdemo/TaosDemoApplication.java
+1
-1
tests/examples/JDBC/taosdemo/src/main/resources/application.properties
...s/JDBC/taosdemo/src/main/resources/application.properties
+2
-2
未找到文件。
cmake/install.inc
浏览文件 @
6fe5202a
...
...
@@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
IF
(
TD_MVN_INSTALLED
)
INSTALL
(
FILES
$
{
LIBRARY_OUTPUT_PATH
}
/
taos
-
jdbcdriver
-
2.0.
19
-
dist
.
jar
DESTINATION
connector
/
jdbc
)
INSTALL
(
FILES
$
{
LIBRARY_OUTPUT_PATH
}
/
taos
-
jdbcdriver
-
2.0.
20
-
dist
.
jar
DESTINATION
connector
/
jdbc
)
ENDIF
()
ELSEIF
(
TD_DARWIN
)
SET
(
TD_MAKE_INSTALL_SH
"${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh"
)
...
...
src/connector/jdbc/CMakeLists.txt
浏览文件 @
6fe5202a
...
...
@@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
ADD_CUSTOM_COMMAND
(
OUTPUT
${
JDBC_CMD_NAME
}
POST_BUILD
COMMAND mvn -Dmaven.test.skip=true install -f
${
CMAKE_CURRENT_SOURCE_DIR
}
/pom.xml
COMMAND
${
CMAKE_COMMAND
}
-E copy
${
CMAKE_CURRENT_SOURCE_DIR
}
/target/taos-jdbcdriver-2.0.
19
-dist.jar
${
LIBRARY_OUTPUT_PATH
}
COMMAND
${
CMAKE_COMMAND
}
-E copy
${
CMAKE_CURRENT_SOURCE_DIR
}
/target/taos-jdbcdriver-2.0.
20
-dist.jar
${
LIBRARY_OUTPUT_PATH
}
COMMAND mvn -Dmaven.test.skip=true clean -f
${
CMAKE_CURRENT_SOURCE_DIR
}
/pom.xml
COMMENT
"build jdbc driver"
)
ADD_CUSTOM_TARGET
(
${
JDBC_TARGET_NAME
}
ALL WORKING_DIRECTORY
${
EXECUTABLE_OUTPUT_PATH
}
DEPENDS
${
JDBC_CMD_NAME
}
)
...
...
src/connector/jdbc/deploy-pom.xml
浏览文件 @
6fe5202a
...
...
@@ -5,7 +5,7 @@
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.
19
</version>
<version>
2.0.
20
</version>
<packaging>
jar
</packaging>
<name>
JDBCDriver
</name>
...
...
src/connector/jdbc/pom.xml
浏览文件 @
6fe5202a
...
...
@@ -3,7 +3,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.
19
</version>
<version>
2.0.
20
</version>
<packaging>
jar
</packaging>
<name>
JDBCDriver
</name>
<url>
https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc
</url>
...
...
@@ -34,23 +34,9 @@
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
<maven-compiler-plugin.version>
3.6.0
</maven-compiler-plugin.version>
<commons-logging.version>
1.1.2
</commons-logging.version>
<commons-lang3.version>
3.5
</commons-lang3.version>
<maven.test.jvmargs></maven.test.jvmargs>
</properties>
<dependencies>
<dependency>
<groupId>
commons-logging
</groupId>
<artifactId>
commons-logging
</artifactId>
<version>
${commons-logging.version}
</version>
<exclusions>
<exclusion>
<groupId>
*
</groupId>
<artifactId>
*
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
...
...
@@ -64,23 +50,12 @@
<artifactId>
httpclient
</artifactId>
<version>
4.5.8
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.9
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.58
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-dbcp2
</artifactId>
<version>
2.7.0
</version>
</dependency>
</dependencies>
<build>
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java
浏览文件 @
6fe5202a
...
...
@@ -126,9 +126,9 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
case
Connection
.
TRANSACTION_READ_COMMITTED
:
case
Connection
.
TRANSACTION_REPEATABLE_READ
:
case
Connection
.
TRANSACTION_SERIALIZABLE
:
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
default
:
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
//do nothing
}
...
...
@@ -436,7 +436,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
@Override
public
void
setClientInfo
(
String
name
,
String
value
)
throws
SQLClientInfoException
{
if
(
isClosed
)
throw
TSDBError
.
createSQLClientInfoException
(
TSDBErrorNumbers
.
ERROR
_CONNECTION_CLOSED
);
throw
(
SQLClientInfoException
)
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_SQLCLIENT_EXCEPTION_ON
_CONNECTION_CLOSED
);
if
(
clientInfoProps
==
null
)
clientInfoProps
=
new
Properties
();
...
...
@@ -446,7 +446,8 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
@Override
public
void
setClientInfo
(
Properties
properties
)
throws
SQLClientInfoException
{
if
(
isClosed
)
throw
TSDBError
.
createSQLClientInfoException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
(
SQLClientInfoException
)
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED
);
for
(
Enumeration
<
Object
>
enumer
=
properties
.
keys
();
enumer
.
hasMoreElements
();
)
{
String
name
=
(
String
)
enumer
.
nextElement
();
...
...
@@ -457,7 +458,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
@Override
public
String
getClientInfo
(
String
name
)
throws
SQLException
{
if
(
isClosed
)
throw
TSDBError
.
createSQL
ClientInfo
Exception
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
clientInfoProps
.
getProperty
(
name
);
}
...
...
@@ -465,7 +466,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
@Override
public
Properties
getClientInfo
()
throws
SQLException
{
if
(
isClosed
)
throw
TSDBError
.
createSQL
ClientInfo
Exception
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
clientInfoProps
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java
浏览文件 @
6fe5202a
package
com.taosdata.jdbc
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.List
;
public
abstract
class
AbstractStatement
extends
WrapperImpl
implements
Statement
{
pr
ivate
volatile
boolean
closeOnCompletion
;
pr
otected
List
<
String
>
batchedArgs
;
private
int
fetchSize
;
@Override
...
...
@@ -45,13 +47,14 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
max
<
0
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
//
nothing to do
//
do nothing
}
@Override
public
void
setEscapeProcessing
(
boolean
enable
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
// do nothing
}
@Override
...
...
@@ -71,6 +74,9 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
@Override
public
void
cancel
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
...
...
@@ -92,6 +98,7 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
void
setCursorName
(
String
name
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
...
...
@@ -113,6 +120,15 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
void
setFetchDirection
(
int
direction
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
switch
(
direction
)
{
case
ResultSet
.
FETCH_FORWARD
:
case
ResultSet
.
FETCH_REVERSE
:
case
ResultSet
.
FETCH_UNKNOWN
:
break
;
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
//nothing to do
}
...
...
@@ -155,13 +171,42 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
}
@Override
public
abstract
void
addBatch
(
String
sql
)
throws
SQLException
;
public
void
addBatch
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
batchedArgs
==
null
)
{
batchedArgs
=
new
ArrayList
<>();
}
batchedArgs
.
add
(
sql
);
}
@Override
public
abstract
void
clearBatch
()
throws
SQLException
;
public
void
clearBatch
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
batchedArgs
!=
null
)
batchedArgs
.
clear
();
}
@Override
public
abstract
int
[]
executeBatch
()
throws
SQLException
;
public
int
[]
executeBatch
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
batchedArgs
==
null
||
batchedArgs
.
isEmpty
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_BATCH_IS_EMPTY
);
int
[]
res
=
new
int
[
batchedArgs
.
size
()];
for
(
int
i
=
0
;
i
<
batchedArgs
.
size
();
i
++)
{
boolean
isSelect
=
execute
(
batchedArgs
.
get
(
i
));
if
(
isSelect
)
{
res
[
i
]
=
SUCCESS_NO_INFO
;
}
else
{
res
[
i
]
=
getUpdateCount
();
}
}
return
res
;
}
@Override
public
abstract
Connection
getConnection
()
throws
SQLException
;
...
...
@@ -170,42 +215,73 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
boolean
getMoreResults
(
int
current
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
return
false
;
switch
(
current
)
{
case
Statement
.
CLOSE_CURRENT_RESULT
:
return
false
;
case
Statement
.
KEEP_CURRENT_RESULT
:
case
Statement
.
CLOSE_ALL_RESULTS
:
break
;
default
:
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
ResultSet
getGeneratedKeys
()
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
int
executeUpdate
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
int
executeUpdate
(
String
sql
,
int
[]
columnIndexes
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
int
executeUpdate
(
String
sql
,
String
[]
columnNames
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
execute
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
execute
(
String
sql
,
int
[]
columnIndexes
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
execute
(
String
sql
,
String
[]
columnNames
)
throws
SQLException
{
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -222,7 +298,7 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
void
setPoolable
(
boolean
poolable
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
//
nothing to do
//
do nothing
}
@Override
...
...
@@ -236,14 +312,15 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public
void
closeOnCompletion
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
this
.
closeOnCompletion
=
true
;
// do nothing
}
@Override
public
boolean
isCloseOnCompletion
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
return
this
.
closeOnCompletion
;
return
false
;
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
浏览文件 @
6fe5202a
...
...
@@ -160,12 +160,12 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
Date
getDate
(
int
columnIndex
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Time
getTime
(
int
columnIndex
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -176,17 +176,17 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
InputStream
getAsciiStream
(
int
columnIndex
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
InputStream
getUnicodeStream
(
int
columnIndex
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
InputStream
getBinaryStream
(
int
columnIndex
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -256,22 +256,22 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
InputStream
getAsciiStream
(
String
columnLabel
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
InputStream
getUnicodeStream
(
String
columnLabel
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
InputStream
getBinaryStream
(
String
columnLabel
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
SQLWarning
getWarnings
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -281,7 +281,7 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
String
getCursorName
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -313,12 +313,12 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
Reader
getCharacterStream
(
int
columnIndex
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Reader
getCharacterStream
(
String
columnLabel
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -353,22 +353,22 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
void
beforeFirst
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
afterLast
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
first
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
last
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -383,17 +383,17 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
boolean
absolute
(
int
row
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
relative
(
int
rows
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
boolean
previous
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -443,227 +443,227 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
void
updateNull
(
int
columnIndex
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateBoolean
(
int
columnIndex
,
boolean
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateByte
(
int
columnIndex
,
byte
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateShort
(
int
columnIndex
,
short
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateInt
(
int
columnIndex
,
int
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateLong
(
int
columnIndex
,
long
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateFloat
(
int
columnIndex
,
float
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateDouble
(
int
columnIndex
,
double
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateBigDecimal
(
int
columnIndex
,
BigDecimal
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateString
(
int
columnIndex
,
String
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateBytes
(
int
columnIndex
,
byte
[]
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateDate
(
int
columnIndex
,
Date
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateTime
(
int
columnIndex
,
Time
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateTimestamp
(
int
columnIndex
,
Timestamp
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateAsciiStream
(
int
columnIndex
,
InputStream
x
,
int
length
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateBinaryStream
(
int
columnIndex
,
InputStream
x
,
int
length
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateCharacterStream
(
int
columnIndex
,
Reader
x
,
int
length
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateObject
(
int
columnIndex
,
Object
x
,
int
scaleOrLength
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateObject
(
int
columnIndex
,
Object
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateNull
(
String
columnLabel
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateBoolean
(
String
columnLabel
,
boolean
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateByte
(
String
columnLabel
,
byte
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateShort
(
String
columnLabel
,
short
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateInt
(
String
columnLabel
,
int
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateLong
(
String
columnLabel
,
long
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateFloat
(
String
columnLabel
,
float
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateDouble
(
String
columnLabel
,
double
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateBigDecimal
(
String
columnLabel
,
BigDecimal
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateString
(
String
columnLabel
,
String
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateBytes
(
String
columnLabel
,
byte
[]
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateDate
(
String
columnLabel
,
Date
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateTime
(
String
columnLabel
,
Time
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateTimestamp
(
String
columnLabel
,
Timestamp
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateAsciiStream
(
String
columnLabel
,
InputStream
x
,
int
length
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateBinaryStream
(
String
columnLabel
,
InputStream
x
,
int
length
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateCharacterStream
(
String
columnLabel
,
Reader
reader
,
int
length
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateObject
(
String
columnLabel
,
Object
x
,
int
scaleOrLength
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateObject
(
String
columnLabel
,
Object
x
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
insertRow
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
updateRow
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
deleteRow
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
refreshRow
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
cancelRowUpdates
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
moveToInsertRow
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
moveToCurrentRow
()
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -673,12 +673,12 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
Object
getObject
(
int
columnIndex
,
Map
<
String
,
Class
<?>>
map
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
Ref
getRef
(
int
columnIndex
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
@@ -1043,12 +1043,12 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
<
T
>
T
getObject
(
int
columnIndex
,
Class
<
T
>
type
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
<
T
>
T
getObject
(
String
columnLabel
,
Class
<
T
>
type
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
浏览文件 @
6fe5202a
...
...
@@ -22,49 +22,47 @@ public class TSDBError {
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
,
"Database not specified or available"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_UPDATE
,
"not a valid sql for executeUpdate: (?)"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE
,
"not a valid sql for execute: (?)"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_RANGE
,
"parameter index out of range"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED
,
"connection already closed"
);
/**************************************************/
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"unknown error"
);
/**************************************************/
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_SUBSCRIBE_FAILED
,
"failed to create subscription"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_ENCODING
,
"Unsupported encoding"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_TDENGINE_ERROR
,
"internal error of database!"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
,
"JNI connection already closed!"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_RESULT_SET_NULL
,
"invalid JNI result set!"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_NUM_OF_FIELDS_0
,
"invalid num of fields!"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_SQL_NULL
,
"empty sql string!"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_FETCH_END
,
"fetch to the end of resultset"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_OUT_OF_MEMORY
,
"JNI alloc memory failed!"
);
}
public
static
String
wrapErrMsg
(
String
msg
)
{
return
"TDengine Error: "
+
msg
;
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_TDENGINE_ERROR
,
"internal error of database"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
,
"JNI connection is NULL"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_RESULT_SET_NULL
,
"JNI result set is NULL"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_NUM_OF_FIELDS_0
,
"invalid num of fields"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_SQL_NULL
,
"empty sql string"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_FETCH_END
,
"fetch to the end of resultSet"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_JNI_OUT_OF_MEMORY
,
"JNI alloc memory failed"
);
}
public
static
SQLException
createSQLException
(
int
errorNumber
)
{
return
createSQLException
(
errorNumber
,
null
);
public
static
SQLException
createSQLException
(
int
errorCode
)
{
String
message
;
if
(
TSDBErrorNumbers
.
contains
(
errorCode
))
message
=
TSDBErrorMap
.
get
(
errorCode
);
else
message
=
TSDBErrorMap
.
get
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
);
return
createSQLException
(
errorCode
,
message
);
}
public
static
SQLException
createSQLException
(
int
error
Number
,
String
message
)
{
if
(
message
==
null
||
message
.
isEmpty
())
{
if
(
TSDBErrorNumbers
.
contains
(
errorNumber
)
)
message
=
TSDBErrorMap
.
get
(
errorNumber
);
else
message
=
TSDBErrorMap
.
get
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
);
}
public
static
SQLException
createSQLException
(
int
error
Code
,
String
message
)
{
// throw SQLFeatureNotSupportedException
if
(
errorCode
==
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
)
return
new
SQLFeatureNotSupportedException
(
message
,
""
,
errorCode
);
// throw SQLClientInfoException
if
(
errorCode
==
TSDBErrorNumbers
.
ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED
)
return
new
SQLClientInfoException
(
message
,
null
);
if
(
errorNumber
==
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
)
return
new
SQLFeatureNotSupportedException
(
message
);
if
(
errorNumber
<
TSDBErrorNumbers
.
ERROR_UNKNOWN
)
if
(
errorCode
>
0x2300
&&
errorCode
<
0x2350
)
// JDBC exception's error number is less than 0x2350
return
new
SQLException
(
"ERROR ("
+
Integer
.
toHexString
(
errorNumber
)
+
"): "
+
message
);
// JNI exception's error number is large than 0x2350
return
new
SQLException
(
"TDengine ERROR ("
+
Integer
.
toHexString
(
errorNumber
)
+
"): "
+
message
);
return
new
SQLException
(
"ERROR ("
+
Integer
.
toHexString
(
errorCode
)
+
"): "
+
message
,
""
,
errorCode
);
if
(
errorCode
>
0x2350
&&
errorCode
<
0x2400
)
// JNI exception's error number is large than 0x2350
return
new
SQLException
(
"JNI ERROR ("
+
Integer
.
toHexString
(
errorCode
)
+
"): "
+
message
,
""
,
errorCode
);
return
new
SQLException
(
"TDengine ERROR ("
+
Integer
.
toHexString
(
errorCode
)
+
"): "
+
message
,
""
,
errorCode
);
}
public
static
SQLClientInfoException
createSQLClientInfoException
(
int
errorNumber
)
{
return
new
SQLClientInfoException
();
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
浏览文件 @
6fe5202a
...
...
@@ -13,22 +13,24 @@ public class TSDBErrorNumbers {
public
static
final
int
ERROR_INVALID_WITH_EXECUTEQUERY
=
0x2307
;
//Can not issue data manipulation statements with executeQuery()
public
static
final
int
ERROR_INVALID_WITH_EXECUTEUPDATE
=
0x2308
;
//Can not issue SELECT via executeUpdate()
public
static
final
int
ERROR_INVALID_FOR_EXECUTE_QUERY
=
0x2309
;
//not a valid sql for executeQuery: (SQL)
public
static
final
int
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
=
0x2310
;
//Database not specified or available
public
static
final
int
ERROR_INVALID_FOR_EXECUTE_UPDATE
=
0x2311
;
//not a valid sql for executeUpdate: (SQL)
public
static
final
int
ERROR_INVALID_FOR_EXECUTE
=
0x2312
;
//not a valid sql for execute: (SQL)
public
static
final
int
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
=
0x230a
;
//Database not specified or available
public
static
final
int
ERROR_INVALID_FOR_EXECUTE_UPDATE
=
0x230b
;
//not a valid sql for executeUpdate: (SQL)
public
static
final
int
ERROR_INVALID_FOR_EXECUTE
=
0x230c
;
//not a valid sql for execute: (SQL)
public
static
final
int
ERROR_PARAMETER_INDEX_OUT_RANGE
=
0x230d
;
// parameter index out of range
public
static
final
int
ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED
=
0x230e
;
// connection already closed
public
static
final
int
ERROR_UNKNOWN
=
0x2350
;
//unknown error
public
static
final
int
ERROR_SUBSCRIBE_FAILED
=
0x2351
;
//
failed to create subscription
public
static
final
int
ERROR_UNSUPPORTED_ENCODING
=
0x2352
;
//Unsupported encoding
public
static
final
int
ERROR_SUBSCRIBE_FAILED
=
0x2351
;
//
failed to create subscription
public
static
final
int
ERROR_UNSUPPORTED_ENCODING
=
0x2352
;
//
Unsupported encoding
public
static
final
int
ERROR_JNI_TDENGINE_ERROR
=
0x2353
;
public
static
final
int
ERROR_JNI_CONNECTION_NULL
=
0x2354
;
//
invalid tdengine connection!
public
static
final
int
ERROR_JNI_RESULT_SET_NULL
=
0x2355
;
public
static
final
int
ERROR_JNI_NUM_OF_FIELDS_0
=
0x2356
;
public
static
final
int
ERROR_JNI_SQL_NULL
=
0x2357
;
public
static
final
int
ERROR_JNI_FETCH_END
=
0x2358
;
public
static
final
int
ERROR_JNI_OUT_OF_MEMORY
=
0x2359
;
public
static
final
int
ERROR_JNI_TDENGINE_ERROR
=
0x2353
;
// internal error of database
public
static
final
int
ERROR_JNI_CONNECTION_NULL
=
0x2354
;
//
JNI connection is NULL
public
static
final
int
ERROR_JNI_RESULT_SET_NULL
=
0x2355
;
// invalid JNI result set
public
static
final
int
ERROR_JNI_NUM_OF_FIELDS_0
=
0x2356
;
// invalid num of fields
public
static
final
int
ERROR_JNI_SQL_NULL
=
0x2357
;
// empty sql string
public
static
final
int
ERROR_JNI_FETCH_END
=
0x2358
;
// fetch to the end of resultSet
public
static
final
int
ERROR_JNI_OUT_OF_MEMORY
=
0x2359
;
// JNI alloc memory failed
private
static
final
HashSet
<
Integer
>
errorNumbers
;
...
...
@@ -45,6 +47,8 @@ public class TSDBErrorNumbers {
errorNumbers
.
add
(
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE_UPDATE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE
);
errorNumbers
.
add
(
ERROR_PARAMETER_INDEX_OUT_RANGE
);
errorNumbers
.
add
(
ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED
);
/*****************************************************/
errorNumbers
.
add
(
ERROR_SUBSCRIBE_FAILED
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
6fe5202a
...
...
@@ -102,7 +102,7 @@ public class TSDBJNIConnector {
this
.
taos
=
this
.
connectImp
(
host
,
port
,
dbName
,
user
,
password
);
if
(
this
.
taos
==
TSDBConstants
.
JNI_NULL_POINTER
)
{
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
this
.
getErrMsg
(
0L
)),
""
,
this
.
getErrCode
(
0
l
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
// invoke connectImp only here
taosInfo
.
conn_open_increment
();
...
...
@@ -187,7 +187,6 @@ public class TSDBJNIConnector {
// public long getResultSet() {
// return taosResultSetPointer;
// }
private
native
long
getResultSetImp
(
long
connection
,
long
pSql
);
public
boolean
isUpdateQuery
(
long
pSql
)
{
...
...
@@ -206,7 +205,7 @@ public class TSDBJNIConnector {
// }
// if (taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
res
=
this
.
freeResultSetImp
(
this
.
taos
,
pSql
);
res
=
this
.
freeResultSetImp
(
this
.
taos
,
pSql
);
// taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
// }
...
...
@@ -227,7 +226,6 @@ public class TSDBJNIConnector {
// }
// return resCode;
// }
private
native
int
freeResultSetImp
(
long
connection
,
long
result
);
/**
...
...
@@ -275,7 +273,7 @@ public class TSDBJNIConnector {
public
void
closeConnection
()
throws
SQLException
{
int
code
=
this
.
closeConnectionImp
(
this
.
taos
);
if
(
code
<
0
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
code
),
""
,
this
.
getErrCode
(
0
l
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
else
if
(
code
==
0
)
{
this
.
taos
=
TSDBConstants
.
JNI_NULL_POINTER
;
}
else
{
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
浏览文件 @
6fe5202a
此差异已折叠。
点击以展开。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
6fe5202a
...
...
@@ -14,17 +14,13 @@
*****************************************************************************/
package
com.taosdata.jdbc
;
import
java.sql.
*
;
import
java.
util.ArrayLis
t
;
import
java.
util.List
;
import
java.sql.
Connection
;
import
java.
sql.ResultSe
t
;
import
java.
sql.SQLException
;
public
class
TSDBStatement
extends
AbstractStatement
{
private
TSDBJNIConnector
connector
;
/**
* To store batched commands
*/
protected
List
<
String
>
batchedArgs
;
/**
* Status of current statement
*/
...
...
@@ -119,41 +115,6 @@ public class TSDBStatement extends AbstractStatement {
return
this
.
affectedRows
;
}
public
void
addBatch
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
batchedArgs
==
null
)
{
batchedArgs
=
new
ArrayList
<>();
}
batchedArgs
.
add
(
sql
);
}
public
void
clearBatch
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
batchedArgs
!=
null
)
batchedArgs
.
clear
();
}
public
int
[]
executeBatch
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
batchedArgs
==
null
||
batchedArgs
.
isEmpty
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_BATCH_IS_EMPTY
);
int
[]
res
=
new
int
[
batchedArgs
.
size
()];
for
(
int
i
=
0
;
i
<
batchedArgs
.
size
();
i
++)
{
boolean
isSelect
=
execute
(
batchedArgs
.
get
(
i
));
if
(
isSelect
)
{
res
[
i
]
=
SUCCESS_NO_INFO
;
}
else
{
res
[
i
]
=
getUpdateCount
();
}
}
return
res
;
}
public
Connection
getConnection
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
浏览文件 @
6fe5202a
...
...
@@ -26,7 +26,8 @@ public class RestfulConnection extends AbstractConnection {
@Override
public
Statement
createStatement
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);;
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
;
return
new
RestfulStatement
(
this
,
database
);
}
...
...
@@ -34,9 +35,8 @@ public class RestfulConnection extends AbstractConnection {
@Override
public
PreparedStatement
prepareStatement
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);;
//TODO: prepareStatement
throw
new
SQLFeatureNotSupportedException
(
TSDBConstants
.
UNSUPPORTED_METHOD_EXCEPTION_MSG
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
new
RestfulPreparedStatement
(
this
,
database
,
sql
);
}
@Override
...
...
@@ -55,7 +55,8 @@ public class RestfulConnection extends AbstractConnection {
@Override
public
DatabaseMetaData
getMetaData
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);;
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
;
return
this
.
metadata
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java
浏览文件 @
6fe5202a
...
...
@@ -5,8 +5,10 @@ import com.alibaba.fastjson.JSONObject;
import
com.taosdata.jdbc.AbstractDriver
;
import
com.taosdata.jdbc.TSDBConstants
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.
rs.util
.HttpClientPoolUtil
;
import
com.taosdata.jdbc.
utils
.HttpClientPoolUtil
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.sql.*
;
import
java.util.Properties
;
import
java.util.logging.Logger
;
...
...
@@ -41,6 +43,15 @@ public class RestfulDriver extends AbstractDriver {
+
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_PORT
)
+
"/rest/login/"
+
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_USER
)
+
"/"
+
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_PASSWORD
)
+
""
;
try
{
String
user
=
URLEncoder
.
encode
(
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_USER
),
"UTF-8"
);
String
password
=
URLEncoder
.
encode
(
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_PASSWORD
),
"UTF-8"
);
loginUrl
=
"http://"
+
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
)
+
":"
+
props
.
getProperty
(
TSDBDriver
.
PROPERTY_KEY_PORT
)
+
"/rest/login/"
+
user
+
"/"
+
password
+
""
;
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
String
result
=
HttpClientPoolUtil
.
execute
(
loginUrl
);
JSONObject
jsonResult
=
JSON
.
parseObject
(
result
);
String
status
=
jsonResult
.
getString
(
"status"
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulPreparedStatement.java
0 → 100644
浏览文件 @
6fe5202a
package
com.taosdata.jdbc.rs
;
import
com.taosdata.jdbc.TSDBError
;
import
com.taosdata.jdbc.TSDBErrorNumbers
;
import
java.io.InputStream
;
import
java.io.Reader
;
import
java.math.BigDecimal
;
import
java.net.URL
;
import
java.sql.*
;
import
java.util.Calendar
;
public
class
RestfulPreparedStatement
extends
RestfulStatement
implements
PreparedStatement
{
private
ParameterMetaData
parameterMetaData
;
private
final
String
rawSql
;
private
Object
[]
parameters
;
private
boolean
isPrepared
;
public
RestfulPreparedStatement
(
RestfulConnection
conn
,
String
database
,
String
sql
)
{
super
(
conn
,
database
);
this
.
rawSql
=
sql
;
if
(
sql
.
contains
(
"?"
))
{
int
parameterCnt
=
0
;
for
(
int
i
=
0
;
i
<
sql
.
length
();
i
++)
{
if
(
'?'
==
sql
.
charAt
(
i
))
{
parameterCnt
++;
}
}
parameters
=
new
Object
[
parameterCnt
];
this
.
isPrepared
=
true
;
}
//TODO: build parameterMetaData
}
@Override
public
ResultSet
executeQuery
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(!
isPrepared
)
return
executeQuery
(
this
.
rawSql
);
final
String
sql
=
getNativeSql
(
this
.
rawSql
);
return
executeQuery
(
sql
);
}
@Override
public
int
executeUpdate
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(!
isPrepared
)
return
executeUpdate
(
this
.
rawSql
);
final
String
sql
=
getNativeSql
(
this
.
rawSql
);
return
executeUpdate
(
sql
);
}
private
String
getNativeSql
(
String
rawSql
)
throws
SQLException
{
String
sql
=
rawSql
;
for
(
int
i
=
0
;
i
<
parameters
.
length
;
++
i
)
{
Object
para
=
parameters
[
i
];
if
(
para
!=
null
)
{
String
paraStr
=
para
.
toString
();
if
(
para
instanceof
Timestamp
||
para
instanceof
String
)
{
paraStr
=
"'"
+
paraStr
+
"'"
;
}
sql
=
sql
.
replaceFirst
(
"[?]"
,
paraStr
);
}
else
{
sql
=
sql
.
replaceFirst
(
"[?]"
,
"NULL"
);
}
}
clearParameters
();
return
sql
;
}
@Override
public
void
setNull
(
int
parameterIndex
,
int
sqlType
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
"NULL"
);
}
@Override
public
void
setBoolean
(
int
parameterIndex
,
boolean
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setByte
(
int
parameterIndex
,
byte
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setShort
(
int
parameterIndex
,
short
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setInt
(
int
parameterIndex
,
int
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setLong
(
int
parameterIndex
,
long
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setFloat
(
int
parameterIndex
,
float
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setDouble
(
int
parameterIndex
,
double
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setBigDecimal
(
int
parameterIndex
,
BigDecimal
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setString
(
int
parameterIndex
,
String
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setBytes
(
int
parameterIndex
,
byte
[]
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setDate
(
int
parameterIndex
,
Date
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setTime
(
int
parameterIndex
,
Time
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setTimestamp
(
int
parameterIndex
,
Timestamp
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setAsciiStream
(
int
parameterIndex
,
InputStream
x
,
int
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setUnicodeStream
(
int
parameterIndex
,
InputStream
x
,
int
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setBinaryStream
(
int
parameterIndex
,
InputStream
x
,
int
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
clearParameters
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
this
.
parameters
=
new
Object
[
parameters
.
length
];
}
@Override
public
void
setObject
(
int
parameterIndex
,
Object
x
,
int
targetSqlType
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setObject
(
int
parameterIndex
,
Object
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
parameterIndex
<
1
&&
parameterIndex
>=
parameters
.
length
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_RANGE
);
parameters
[
parameterIndex
-
1
]
=
x
;
}
@Override
public
boolean
execute
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(!
isPrepared
)
return
execute
(
this
.
rawSql
);
final
String
sql
=
getNativeSql
(
rawSql
);
return
execute
(
sql
);
}
@Override
public
void
addBatch
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
final
String
sql
=
getNativeSql
(
this
.
rawSql
);
addBatch
(
sql
);
}
@Override
public
void
setCharacterStream
(
int
parameterIndex
,
Reader
reader
,
int
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setRef
(
int
parameterIndex
,
Ref
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setBlob
(
int
parameterIndex
,
Blob
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setClob
(
int
parameterIndex
,
Clob
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setArray
(
int
parameterIndex
,
Array
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
ResultSetMetaData
getMetaData
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setDate
(
int
parameterIndex
,
Date
x
,
Calendar
cal
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setTime
(
int
parameterIndex
,
Time
x
,
Calendar
cal
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setTimestamp
(
int
parameterIndex
,
Timestamp
x
,
Calendar
cal
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setNull
(
int
parameterIndex
,
int
sqlType
,
String
typeName
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setURL
(
int
parameterIndex
,
URL
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
ParameterMetaData
getParameterMetaData
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
// throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
return
this
.
parameterMetaData
;
}
@Override
public
void
setRowId
(
int
parameterIndex
,
RowId
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setNString
(
int
parameterIndex
,
String
value
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setNCharacterStream
(
int
parameterIndex
,
Reader
value
,
long
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setNClob
(
int
parameterIndex
,
NClob
value
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setClob
(
int
parameterIndex
,
Reader
reader
,
long
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setBlob
(
int
parameterIndex
,
InputStream
inputStream
,
long
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setNClob
(
int
parameterIndex
,
Reader
reader
,
long
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setSQLXML
(
int
parameterIndex
,
SQLXML
xmlObject
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setObject
(
int
parameterIndex
,
Object
x
,
int
targetSqlType
,
int
scaleOrLength
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setAsciiStream
(
int
parameterIndex
,
InputStream
x
,
long
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setBinaryStream
(
int
parameterIndex
,
InputStream
x
,
long
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setCharacterStream
(
int
parameterIndex
,
Reader
reader
,
long
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setAsciiStream
(
int
parameterIndex
,
InputStream
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setBinaryStream
(
int
parameterIndex
,
InputStream
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setCharacterStream
(
int
parameterIndex
,
Reader
reader
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setNCharacterStream
(
int
parameterIndex
,
Reader
value
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setClob
(
int
parameterIndex
,
Reader
reader
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setBlob
(
int
parameterIndex
,
InputStream
inputStream
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
@Override
public
void
setNClob
(
int
parameterIndex
,
Reader
reader
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
浏览文件 @
6fe5202a
...
...
@@ -106,7 +106,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
boolean
next
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
pos
++;
if
(
pos
<=
resultSet
.
size
()
-
1
)
{
return
true
;
...
...
@@ -124,14 +124,14 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
boolean
wasNull
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
return
resultSet
.
isEmpty
();
}
@Override
public
String
getString
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
if
(
columnIndex
>
resultSet
.
get
(
pos
).
size
())
{
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
"Column Index out of range, "
+
columnIndex
+
" > "
+
resultSet
.
get
(
pos
).
size
()));
...
...
@@ -144,7 +144,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
boolean
getBoolean
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
columnIndex
=
getTrueColumnIndex
(
columnIndex
);
int
result
=
getInt
(
columnIndex
);
...
...
@@ -154,7 +154,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
short
getShort
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
columnIndex
=
getTrueColumnIndex
(
columnIndex
);
return
Short
.
parseShort
(
resultSet
.
get
(
pos
).
get
(
columnIndex
).
toString
());
}
...
...
@@ -162,7 +162,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
int
getInt
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
columnIndex
=
getTrueColumnIndex
(
columnIndex
);
return
Integer
.
parseInt
(
resultSet
.
get
(
pos
).
get
(
columnIndex
).
toString
());
}
...
...
@@ -170,7 +170,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
long
getLong
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
columnIndex
=
getTrueColumnIndex
(
columnIndex
);
return
Long
.
parseLong
(
resultSet
.
get
(
pos
).
get
(
columnIndex
).
toString
());
}
...
...
@@ -178,7 +178,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
float
getFloat
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
columnIndex
=
getTrueColumnIndex
(
columnIndex
);
return
Float
.
parseFloat
(
resultSet
.
get
(
pos
).
get
(
columnIndex
).
toString
());
}
...
...
@@ -186,7 +186,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
double
getDouble
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
columnIndex
=
getTrueColumnIndex
(
columnIndex
);
return
Double
.
parseDouble
(
resultSet
.
get
(
pos
).
get
(
columnIndex
).
toString
());
...
...
@@ -208,7 +208,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
Timestamp
getTimestamp
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
columnIndex
=
getTrueColumnIndex
(
columnIndex
);
String
strDate
=
resultSet
.
get
(
pos
).
get
(
columnIndex
).
toString
();
...
...
@@ -220,7 +220,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
ResultSetMetaData
getMetaData
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
return
this
.
metaData
;
}
...
...
@@ -233,7 +233,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
int
findColumn
(
String
columnLabel
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
int
columnIndex
=
columnNames
.
indexOf
(
columnLabel
);
if
(
columnIndex
==
-
1
)
...
...
@@ -244,14 +244,14 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
boolean
isBeforeFirst
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
return
this
.
pos
==
-
1
&&
this
.
resultSet
.
size
()
!=
0
;
}
@Override
public
boolean
isAfterLast
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
return
this
.
pos
>=
resultSet
.
size
()
&&
this
.
resultSet
.
size
()
!=
0
;
}
...
...
@@ -259,14 +259,14 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
boolean
isFirst
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
return
this
.
pos
==
0
;
}
@Override
public
boolean
isLast
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
if
(
this
.
resultSet
.
size
()
==
0
)
return
false
;
return
this
.
pos
==
(
this
.
resultSet
.
size
()
-
1
);
...
...
@@ -275,7 +275,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
void
beforeFirst
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
synchronized
(
this
)
{
if
(
this
.
resultSet
.
size
()
>
0
)
{
...
...
@@ -287,7 +287,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
void
afterLast
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
synchronized
(
this
)
{
if
(
this
.
resultSet
.
size
()
>
0
)
{
this
.
pos
=
this
.
resultSet
.
size
();
...
...
@@ -298,7 +298,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
boolean
first
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
if
(
this
.
resultSet
.
size
()
==
0
)
return
false
;
...
...
@@ -312,7 +312,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
boolean
last
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
if
(
this
.
resultSet
.
size
()
==
0
)
return
false
;
synchronized
(
this
)
{
...
...
@@ -324,7 +324,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
int
getRow
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
int
row
;
synchronized
(
this
)
{
if
(
this
.
pos
<
0
||
this
.
pos
>=
this
.
resultSet
.
size
())
...
...
@@ -396,7 +396,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
@Override
public
Statement
getStatement
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
TSDBConstants
.
RESULT_SET_IS_CLOSED
)
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
return
this
.
statement
;
}
...
...
@@ -407,5 +407,4 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
浏览文件 @
6fe5202a
package
com.taosdata.jdbc.rs
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.taosdata.jdbc.AbstractStatement
;
import
com.taosdata.jdbc.TSDBConstants
;
import
com.taosdata.jdbc.TSDBError
;
import
com.taosdata.jdbc.TSDBErrorNumbers
;
import
com.taosdata.jdbc.
rs.util
.HttpClientPoolUtil
;
import
com.taosdata.jdbc.
utils
.HttpClientPoolUtil
;
import
com.taosdata.jdbc.utils.SqlSyntaxValidator
;
import
java.sql.*
;
...
...
@@ -29,7 +30,7 @@ public class RestfulStatement extends AbstractStatement {
this
.
database
=
database
;
}
pr
ivate
String
[]
parseTableIdentifier
(
String
sql
)
{
pr
otected
String
[]
parseTableIdentifier
(
String
sql
)
{
sql
=
sql
.
trim
().
toLowerCase
();
String
[]
ret
=
null
;
if
(
sql
.
contains
(
"where"
))
...
...
@@ -74,8 +75,8 @@ public class RestfulStatement extends AbstractStatement {
return
executeOneQuery
(
url
,
sql
);
}
if
(
this
.
database
==
null
||
this
.
database
.
isEmpty
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
);
//
if (this.database == null || this.database.isEmpty())
//
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
HttpClientPoolUtil
.
execute
(
url
,
"use "
+
this
.
database
);
return
executeOneQuery
(
url
,
sql
);
}
...
...
@@ -92,8 +93,8 @@ public class RestfulStatement extends AbstractStatement {
return
executeOneUpdate
(
url
,
sql
);
}
if
(
this
.
database
==
null
||
this
.
database
.
isEmpty
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
);
//
if (this.database == null || this.database.isEmpty())
//
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
HttpClientPoolUtil
.
execute
(
url
,
"use "
+
this
.
database
);
return
executeOneUpdate
(
url
,
sql
);
...
...
@@ -115,24 +116,28 @@ public class RestfulStatement extends AbstractStatement {
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE
,
"not a valid sql for execute: "
+
sql
);
//如果执行了use操作应该将当前Statement的catalog设置为新的database
boolean
result
=
true
;
final
String
url
=
"http://"
+
conn
.
getHost
()
+
":"
+
conn
.
getPort
()
+
"/rest/sql"
;
if
(
SqlSyntaxValidator
.
isUseSql
(
sql
))
{
HttpClientPoolUtil
.
execute
(
url
,
sql
);
this
.
database
=
sql
.
trim
().
replace
(
"use"
,
""
).
trim
();
this
.
conn
.
setCatalog
(
this
.
database
);
result
=
false
;
}
else
if
(
SqlSyntaxValidator
.
isDatabaseUnspecifiedQuery
(
sql
))
{
executeOneQuery
(
url
,
sql
);
}
else
if
(
SqlSyntaxValidator
.
isDatabaseUnspecifiedUpdate
(
sql
))
{
executeOneUpdate
(
url
,
sql
);
result
=
false
;
}
else
{
if
(
SqlSyntaxValidator
.
isValidForExecuteQuery
(
sql
))
{
executeQuery
(
sql
);
}
else
{
executeUpdate
(
sql
);
result
=
false
;
}
}
return
true
;
return
result
;
}
private
ResultSet
executeOneQuery
(
String
url
,
String
sql
)
throws
SQLException
{
...
...
@@ -176,10 +181,23 @@ public class RestfulStatement extends AbstractStatement {
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
"SQL execution error: "
+
jsonObject
.
getString
(
"desc"
)
+
"\n"
+
"error code: "
+
jsonObject
.
getString
(
"code"
)));
}
this
.
resultSet
=
null
;
this
.
affectedRows
=
Integer
.
parseInt
(
jsonObject
.
getString
(
"rows"
)
);
this
.
affectedRows
=
checkJsonResultSet
(
jsonObject
);
return
this
.
affectedRows
;
}
private
int
checkJsonResultSet
(
JSONObject
jsonObject
)
{
// create ... SQLs should return 0 , and Restful result is this:
// {"status": "succ", "head": ["affected_rows"], "data": [[0]], "rows": 1}
JSONArray
head
=
jsonObject
.
getJSONArray
(
"head"
);
JSONArray
data
=
jsonObject
.
getJSONArray
(
"data"
);
int
rows
=
Integer
.
parseInt
(
jsonObject
.
getString
(
"rows"
));
if
(
head
.
size
()
==
1
&&
"affected_rows"
.
equals
(
head
.
getString
(
0
))
&&
data
.
size
()
==
1
&&
data
.
getJSONArray
(
0
).
getInteger
(
0
)
==
0
&&
rows
==
1
)
{
return
0
;
}
return
rows
;
}
@Override
public
ResultSet
getResultSet
()
throws
SQLException
{
if
(
isClosed
())
...
...
@@ -195,24 +213,6 @@ public class RestfulStatement extends AbstractStatement {
return
this
.
affectedRows
;
}
@Override
public
void
addBatch
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
//TODO:
}
@Override
public
void
clearBatch
()
throws
SQLException
{
//TODO:
}
@Override
public
int
[]
executeBatch
()
throws
SQLException
{
//TODO:
return
new
int
[
0
];
}
@Override
public
Connection
getConnection
()
throws
SQLException
{
if
(
isClosed
())
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/
rs/util
/HttpClientPoolUtil.java
→
src/connector/jdbc/src/main/java/com/taosdata/jdbc/
utils
/HttpClientPoolUtil.java
浏览文件 @
6fe5202a
package
com.taosdata.jdbc.
rs.util
;
package
com.taosdata.jdbc.
utils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.HeaderElement
;
import
org.apache.http.HeaderElementIterator
;
import
org.apache.http.HttpEntity
;
...
...
@@ -39,7 +38,7 @@ public class HttpClientPoolUtil {
/**
* 初始化连接池
*/
p
ublic
static
synchronized
void
initPools
()
{
p
rivate
static
synchronized
void
initPools
()
{
if
(
httpClient
==
null
)
{
cm
=
new
PoolingHttpClientConnectionManager
();
cm
.
setDefaultMaxPerRoute
(
count
);
...
...
@@ -51,7 +50,7 @@ public class HttpClientPoolUtil {
/**
* Http connection keepAlive 设置
*/
p
ublic
static
ConnectionKeepAliveStrategy
defaultStrategy
=
(
response
,
context
)
->
{
p
rivate
static
ConnectionKeepAliveStrategy
defaultStrategy
=
(
response
,
context
)
->
{
HeaderElementIterator
it
=
new
BasicHeaderElementIterator
(
response
.
headerIterator
(
HTTP
.
CONN_KEEP_ALIVE
));
int
keepTime
=
Http_Default_Keep_Time
*
1000
;
while
(
it
.
hasNext
())
{
...
...
@@ -69,14 +68,6 @@ public class HttpClientPoolUtil {
return
keepTime
;
};
public
static
CloseableHttpClient
getHttpClient
()
{
return
httpClient
;
}
public
static
PoolingHttpClientConnectionManager
getHttpConnectionManager
()
{
return
cm
;
}
/**
* 执行http post请求
* 默认采用Content-Type:application/json,Accept:application/json
...
...
@@ -95,8 +86,10 @@ public class HttpClientPoolUtil {
initPools
();
}
method
=
(
HttpEntityEnclosingRequestBase
)
getRequest
(
uri
,
HttpPost
.
METHOD_NAME
,
DEFAULT_CONTENT_TYPE
,
0
);
method
.
setHeader
(
"Authorization"
,
"Taosd "
+
token
);
method
.
setHeader
(
"Content-Type"
,
"text/plain"
);
method
.
setHeader
(
"Connection"
,
"keep-alive"
);
method
.
setHeader
(
"Authorization"
,
"Taosd "
+
token
);
method
.
setEntity
(
new
StringEntity
(
data
,
Charset
.
forName
(
"UTF-8"
)));
HttpContext
context
=
HttpClientContext
.
create
();
CloseableHttpResponse
httpResponse
=
httpClient
.
execute
(
method
,
context
);
...
...
@@ -131,7 +124,7 @@ public class HttpClientPoolUtil {
* @return HttpRequestBase 返回类型
* @author lisc
*/
p
ublic
static
HttpRequestBase
getRequest
(
String
uri
,
String
methodName
,
String
contentType
,
int
timeout
)
{
p
rivate
static
HttpRequestBase
getRequest
(
String
uri
,
String
methodName
,
String
contentType
,
int
timeout
)
{
if
(
httpClient
==
null
)
{
initPools
();
}
...
...
@@ -152,7 +145,7 @@ public class HttpClientPoolUtil {
method
=
new
HttpPost
(
uri
);
}
if
(
StringUtils
.
isBlank
(
contentType
))
{
if
(
contentType
==
null
||
contentType
.
isEmpty
()
||
contentType
.
replaceAll
(
"\\s"
,
""
).
isEmpty
(
))
{
contentType
=
DEFAULT_CONTENT_TYPE
;
}
method
.
addHeader
(
"Content-Type"
,
contentType
);
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java
已删除
100644 → 0
浏览文件 @
f4399816
package
com.taosdata.jdbc
;
import
org.junit.*
;
import
org.junit.runners.MethodSorters
;
import
java.sql.*
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@FixMethodOrder
(
value
=
MethodSorters
.
NAME_ASCENDING
)
public
class
PreparedStatementTest
{
static
Connection
connection
;
static
TSDBPreparedStatement
statement
;
static
String
dbName
=
"test"
;
static
String
tName
=
"t0"
;
static
String
host
=
"localhost"
;
@BeforeClass
public
static
void
createConnection
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
,
properties
);
String
sql
=
"drop database if exists "
+
dbName
;
statement
=
(
TSDBPreparedStatement
)
connection
.
prepareStatement
(
sql
);
}
@Test
public
void
case001_createTableAndQuery
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
"(ts timestamp, k1 int)"
);
statement
.
executeUpdate
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", 1)"
);
PreparedStatement
selectStatement
=
connection
.
prepareStatement
(
"select * from "
+
dbName
+
"."
+
tName
);
ResultSet
resultSet
=
selectStatement
.
executeQuery
();
assertTrue
(
null
!=
resultSet
);
boolean
isClosed
=
statement
.
isClosed
();
assertEquals
(
false
,
isClosed
);
selectStatement
.
close
();
}
@Test
public
void
case002_testPreparedStatement
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
()
+
20000
;
PreparedStatement
saveStatement
=
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", 1)"
);
int
affectedRows
=
saveStatement
.
executeUpdate
();
assertTrue
(
1
==
affectedRows
);
saveStatement
.
close
();
}
@Test
public
void
case003_testSavedPreparedStatement
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
();
TSDBPreparedStatement
saveStatement
=
(
TSDBPreparedStatement
)
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values (?, ?)"
);
saveStatement
.
setObject
(
1
,
ts
+
10000
);
saveStatement
.
setObject
(
2
,
3
);
int
rows
=
saveStatement
.
executeUpdate
();
assertEquals
(
1
,
rows
);
saveStatement
.
close
();
}
@Test
public
void
case004_testUnsupport
()
throws
SQLException
{
Assert
.
assertNotNull
(
statement
.
unwrap
(
TSDBPreparedStatement
.
class
));
Assert
.
assertTrue
(
statement
.
isWrapperFor
(
TSDBPreparedStatement
.
class
));
try
{
statement
.
getMaxFieldSize
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
setMaxFieldSize
(
0
);
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
setEscapeProcessing
(
true
);
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
cancel
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getWarnings
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
clearWarnings
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
setCursorName
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getMoreResults
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
setFetchDirection
(
0
);
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getFetchDirection
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getResultSetConcurrency
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getResultSetType
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getConnection
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getMoreResults
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getGeneratedKeys
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
executeUpdate
(
null
,
0
);
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
executeUpdate
(
null
,
new
int
[]{
0
});
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
executeUpdate
(
null
,
new
String
[]{
"str1"
,
"str2"
});
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
getResultSetHoldability
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
setPoolable
(
true
);
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
isPoolable
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
closeOnCompletion
();
}
catch
(
SQLException
e
)
{
}
try
{
statement
.
isCloseOnCompletion
();
}
catch
(
SQLException
e
)
{
}
}
@AfterClass
public
static
void
close
()
throws
Exception
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
Thread
.
sleep
(
10
);
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
浏览文件 @
6fe5202a
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.*
;
public
class
TSDBPreparedStatementTest
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
Connection
conn
;
@Test
public
void
executeQuery
()
{
private
static
final
String
sql_insert
=
"insert into t1 values(?, ?)"
;
private
static
PreparedStatement
pstmt_insert
;
private
static
final
String
sql_select
=
"select * from t1 where ts > ? and ts <= ? and temperature >= ?"
;
private
static
PreparedStatement
pstmt_select
;
@Test
public
void
executeQuery
()
throws
SQLException
{
long
end
=
System
.
currentTimeMillis
();
long
start
=
end
-
1000
*
60
*
60
;
pstmt_select
.
setTimestamp
(
1
,
new
Timestamp
(
start
));
pstmt_select
.
setTimestamp
(
2
,
new
Timestamp
(
end
));
pstmt_select
.
setFloat
(
3
,
0
);
ResultSet
rs
=
pstmt_select
.
executeQuery
();
Assert
.
assertNotNull
(
rs
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
i
)
+
": "
+
rs
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
}
}
@Test
public
void
executeUpdate
()
{
public
void
executeUpdate
()
throws
SQLException
{
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setFloat
(
2
,
3.14f
);
int
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
}
@Test
public
void
setNull
()
{
public
void
setNull
()
throws
SQLException
{
pstmt_insert
.
setNull
(
2
,
Types
.
FLOAT
);
}
@Test
public
void
setBoolean
()
{
public
void
setBoolean
()
throws
SQLException
{
pstmt_insert
.
setBoolean
(
2
,
true
);
}
@Test
public
void
setByte
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setByte
()
throws
SQLException
{
pstmt_insert
.
setByte
(
1
,
(
byte
)
0x001
);
}
@Test
public
void
setShort
()
{
}
@Test
public
void
setInt
()
{
}
@Test
public
void
setLong
()
{
}
@Test
public
void
setFloat
()
{
}
@Test
public
void
setDouble
()
{
}
@Test
public
void
setBigDecimal
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBigDecimal
()
throws
SQLException
{
pstmt_insert
.
setBigDecimal
(
1
,
null
);
}
@Test
public
void
setString
()
{
}
@Test
public
void
setBytes
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBytes
()
throws
SQLException
{
pstmt_insert
.
setBytes
(
1
,
new
byte
[]{});
}
@Test
public
void
setDate
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setDate
()
throws
SQLException
{
pstmt_insert
.
setDate
(
1
,
new
Date
(
System
.
currentTimeMillis
()));
}
@Test
public
void
setTime
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setTime
()
throws
SQLException
{
pstmt_insert
.
setTime
(
1
,
new
Time
(
System
.
currentTimeMillis
()));
}
@Test
public
void
setTimestamp
()
{
//TODO
}
@Test
public
void
setAsciiStream
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setAsciiStream
()
throws
SQLException
{
pstmt_insert
.
setAsciiStream
(
1
,
null
);
}
@Test
public
void
setUnicodeStream
()
{
}
@Test
public
void
setBinaryStream
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBinaryStream
()
throws
SQLException
{
pstmt_insert
.
setBinaryStream
(
1
,
null
);
}
@Test
public
void
clearParameters
()
{
//TODO
}
@Test
public
void
setObject
()
{
public
void
setObject
()
throws
SQLException
{
pstmt_insert
.
setObject
(
1
,
System
.
currentTimeMillis
());
//TODO
}
@Test
public
void
execute
()
{
//TODO
}
@Test
public
void
addBatch
()
{
//TODO:
}
@Test
public
void
setCharacterStream
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setCharacterStream
()
throws
SQLException
{
pstmt_insert
.
setCharacterStream
(
1
,
null
);
}
@Test
public
void
setRef
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setRef
()
throws
SQLException
{
pstmt_insert
.
setRef
(
1
,
null
);
}
@Test
public
void
setBlob
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBlob
()
throws
SQLException
{
pstmt_insert
.
setBlob
(
1
,
(
Blob
)
null
);
}
@Test
public
void
setClob
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setClob
()
throws
SQLException
{
pstmt_insert
.
setClob
(
1
,
(
Clob
)
null
);
}
@Test
public
void
setArray
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setArray
()
throws
SQLException
{
pstmt_insert
.
setArray
(
1
,
null
);
}
@Test
public
void
getMetaData
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getMetaData
()
throws
SQLException
{
pstmt_insert
.
getMetaData
();
}
@Test
public
void
setURL
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setURL
()
throws
SQLException
{
pstmt_insert
.
setURL
(
1
,
null
);
}
@Test
public
void
getParameterMetaData
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getParameterMetaData
()
throws
SQLException
{
ParameterMetaData
parameterMetaData
=
pstmt_insert
.
getParameterMetaData
();
// Assert.assertNotNull(parameterMetaData);
//TODO:
}
@Test
public
void
setRowId
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setRowId
()
throws
SQLException
{
pstmt_insert
.
setRowId
(
1
,
null
);
}
@Test
public
void
setNString
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNString
()
throws
SQLException
{
pstmt_insert
.
setNString
(
1
,
null
);
}
@Test
public
void
setNCharacterStream
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNCharacterStream
()
throws
SQLException
{
pstmt_insert
.
setNCharacterStream
(
1
,
null
);
}
@Test
public
void
setNClob
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNClob
()
throws
SQLException
{
pstmt_insert
.
setNClob
(
1
,
(
NClob
)
null
);
}
@Test
public
void
setSQLXML
()
{
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setSQLXML
()
throws
SQLException
{
pstmt_insert
.
setSQLXML
(
1
,
null
);
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.
rs.Restful
Driver"
);
Class
.
forName
(
"com.taosdata.jdbc.
TSDB
Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
);
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"drop database if exists test_pstmt"
);
stmt
.
execute
(
"create database if not exists test_pstmt"
);
stmt
.
execute
(
"use test_pstmt"
);
stmt
.
execute
(
"create table weather(ts timestamp, temperature float) tags(loc nchar(64))"
);
stmt
.
execute
(
"create table t1 using weather tags('beijing')"
);
}
pstmt_insert
=
conn
.
prepareStatement
(
sql_insert
);
pstmt_select
=
conn
.
prepareStatement
(
sql_select
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -176,6 +231,7 @@ public class TSDBPreparedStatementTest {
@AfterClass
public
static
void
afterClass
()
{
try
{
if
(
conn
!=
null
)
conn
.
close
();
}
catch
(
SQLException
e
)
{
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
浏览文件 @
6fe5202a
...
...
@@ -51,6 +51,68 @@ public class TSDBStatementTest {
@Test
public
void
close
()
{
// test in AfterClass method
}
@Test
public
void
getMaxFieldSize
()
throws
SQLException
{
Assert
.
assertEquals
(
16
*
1024
,
stmt
.
getMaxFieldSize
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setMaxFieldSize
()
throws
SQLException
{
stmt
.
setMaxFieldSize
(
0
);
stmt
.
setMaxFieldSize
(-
1
);
}
@Test
public
void
getMaxRows
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
stmt
.
getMaxRows
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setMaxRows
()
throws
SQLException
{
stmt
.
setMaxRows
(
0
);
stmt
.
setMaxRows
(-
1
);
}
@Test
public
void
setEscapeProcessing
()
throws
SQLException
{
stmt
.
setEscapeProcessing
(
true
);
stmt
.
setEscapeProcessing
(
false
);
}
@Test
public
void
getQueryTimeout
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
stmt
.
getQueryTimeout
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setQueryTimeout
()
throws
SQLException
{
stmt
.
setQueryTimeout
(
0
);
stmt
.
setQueryTimeout
(-
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
cancel
()
throws
SQLException
{
stmt
.
cancel
();
}
@Test
public
void
getWarnings
()
throws
SQLException
{
Assert
.
assertNull
(
stmt
.
getWarnings
());
}
@Test
public
void
clearWarnings
()
throws
SQLException
{
stmt
.
clearWarnings
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setCursorName
()
throws
SQLException
{
stmt
.
setCursorName
(
""
);
}
@Test
...
...
@@ -130,7 +192,48 @@ public class TSDBStatementTest {
@Test
public
void
getUpdateCount
()
{
execute
();
// already test in execute method
}
@Test
public
void
getMoreResults
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
getMoreResults
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setFetchDirection
()
throws
SQLException
{
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_FORWARD
);
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_REVERSE
);
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_UNKNOWN
);
stmt
.
setFetchDirection
(-
1
);
}
@Test
public
void
getFetchDirection
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
FETCH_FORWARD
,
stmt
.
getFetchDirection
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setFetchSize
()
throws
SQLException
{
stmt
.
setFetchSize
(
0
);
stmt
.
setFetchSize
(-
1
);
}
@Test
public
void
getFetchSize
()
throws
SQLException
{
stmt
.
setFetchSize
(
0
);
Assert
.
assertEquals
(
0
,
stmt
.
getFetchSize
());
stmt
.
setFetchSize
(
0
);
}
@Test
public
void
getResultSetConcurrency
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
CONCUR_READ_ONLY
,
stmt
.
getResultSetConcurrency
());
}
@Test
public
void
getResultSetType
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
TYPE_FORWARD_ONLY
,
stmt
.
getResultSetType
());
}
@Test
...
...
@@ -194,6 +297,52 @@ public class TSDBStatementTest {
}
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testGetMoreResults
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
getMoreResults
(
Statement
.
CLOSE_CURRENT_RESULT
));
stmt
.
getMoreResults
(
Statement
.
KEEP_CURRENT_RESULT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getGeneratedKeys
()
throws
SQLException
{
stmt
.
getGeneratedKeys
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate1
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
new
int
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate2
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
new
String
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecute
()
throws
SQLException
{
stmt
.
execute
(
""
,
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecute1
()
throws
SQLException
{
stmt
.
execute
(
""
,
new
int
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecute2
()
throws
SQLException
{
stmt
.
execute
(
""
,
new
String
[]{});
}
@Test
public
void
getResultSetHoldability
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
,
stmt
.
getResultSetHoldability
());
}
@Test
public
void
isClosed
()
{
try
{
...
...
@@ -203,6 +352,38 @@ public class TSDBStatementTest {
}
}
@Test
public
void
setPoolable
()
throws
SQLException
{
stmt
.
setPoolable
(
true
);
stmt
.
setPoolable
(
false
);
}
@Test
public
void
isPoolable
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
isPoolable
());
}
@Test
public
void
closeOnCompletion
()
throws
SQLException
{
stmt
.
closeOnCompletion
();
}
@Test
public
void
isCloseOnCompletion
()
throws
SQLException
{
Assert
.
assertFalse
(
stmt
.
isCloseOnCompletion
());
}
@Test
public
void
unwrap
()
throws
SQLException
{
TSDBStatement
unwrap
=
stmt
.
unwrap
(
TSDBStatement
.
class
);
Assert
.
assertNotNull
(
unwrap
);
}
@Test
public
void
isWrapperFor
()
throws
SQLException
{
Assert
.
assertTrue
(
stmt
.
isWrapperFor
(
TSDBStatement
.
class
));
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java
浏览文件 @
6fe5202a
package
com.taosdata.jdbc.cases
;
import
com.taosdata.jdbc.TSDBErrorNumbers
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -16,8 +17,7 @@ public class ConnectWrongDatabaseTest {
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
Assert
.
assertEquals
(
"TDengine Error: Invalid database name"
,
e
.
getMessage
());
Assert
.
assertEquals
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
,
e
.
getErrorCode
());
}
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java
浏览文件 @
6fe5202a
...
...
@@ -12,7 +12,7 @@ import static org.junit.Assert.assertEquals;
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
public
class
ImportTest
{
private
static
Connection
connection
;
static
String
dbName
=
"test"
;
static
String
dbName
=
"test
_import
"
;
static
String
tName
=
"t0"
;
static
String
host
=
"127.0.0.1"
;
private
static
long
ts
;
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java
浏览文件 @
6fe5202a
...
...
@@ -10,7 +10,7 @@ public class AuthenticationTest {
private
static
final
String
host
=
"127.0.0.1"
;
// private static final String host = "master";
private
static
final
String
user
=
"root"
;
private
static
final
String
password
=
"
123456
"
;
private
static
final
String
password
=
"
taos?data
"
;
private
Connection
conn
;
@Test
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java
浏览文件 @
6fe5202a
package
com.taosdata.jdbc.rs
;
import
com.taosdata.jdbc.TSDBConnection
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.TSDBResultSet
;
import
com.taosdata.jdbc.TSDBSubscribe
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
javax.management.OperationsException
;
import
java.sql.*
;
import
java.util.Properties
;
...
...
@@ -17,6 +13,7 @@ public class RestfulConnectionTest {
private
static
final
String
host
=
"127.0.0.1"
;
// private static final String host = "master";
private
static
Connection
conn
;
@Test
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java
0 → 100644
浏览文件 @
6fe5202a
package
com.taosdata.jdbc.rs
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.*
;
public
class
RestfulPreparedStatementTest
{
private
static
final
String
host
=
"127.0.0.1"
;
// private static final String host = "master";
private
static
Connection
conn
;
private
static
final
String
sql_insert
=
"insert into t1 values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
;
private
static
PreparedStatement
pstmt_insert
;
private
static
final
String
sql_select
=
"select * from t1 where ts > ? and ts <= ? and f1 >= ?"
;
private
static
PreparedStatement
pstmt_select
;
@Test
public
void
executeQuery
()
throws
SQLException
{
long
end
=
System
.
currentTimeMillis
();
long
start
=
end
-
1000
*
60
*
60
;
pstmt_select
.
setTimestamp
(
1
,
new
Timestamp
(
start
));
pstmt_select
.
setTimestamp
(
2
,
new
Timestamp
(
end
));
pstmt_select
.
setInt
(
3
,
0
);
ResultSet
rs
=
pstmt_select
.
executeQuery
();
Assert
.
assertNotNull
(
rs
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
i
)
+
": "
+
rs
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
}
}
@Test
public
void
executeUpdate
()
throws
SQLException
{
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setFloat
(
2
,
3.14f
);
int
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
}
@Test
public
void
setNull
()
throws
SQLException
{
pstmt_insert
.
setNull
(
2
,
Types
.
FLOAT
);
}
@Test
public
void
setBoolean
()
throws
SQLException
{
pstmt_insert
.
setBoolean
(
2
,
true
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setByte
()
throws
SQLException
{
pstmt_insert
.
setByte
(
1
,
(
byte
)
0x001
);
}
@Test
public
void
setShort
()
{
}
@Test
public
void
setInt
()
{
}
@Test
public
void
setLong
()
{
}
@Test
public
void
setFloat
()
{
}
@Test
public
void
setDouble
()
{
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBigDecimal
()
throws
SQLException
{
pstmt_insert
.
setBigDecimal
(
1
,
null
);
}
@Test
public
void
setString
()
{
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBytes
()
throws
SQLException
{
pstmt_insert
.
setBytes
(
1
,
new
byte
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setDate
()
throws
SQLException
{
pstmt_insert
.
setDate
(
1
,
new
Date
(
System
.
currentTimeMillis
()));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setTime
()
throws
SQLException
{
pstmt_insert
.
setTime
(
1
,
new
Time
(
System
.
currentTimeMillis
()));
}
@Test
public
void
setTimestamp
()
{
//TODO
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setAsciiStream
()
throws
SQLException
{
pstmt_insert
.
setAsciiStream
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBinaryStream
()
throws
SQLException
{
pstmt_insert
.
setBinaryStream
(
1
,
null
);
}
@Test
public
void
clearParameters
()
{
//TODO
}
@Test
public
void
setObject
()
throws
SQLException
{
pstmt_insert
.
setObject
(
1
,
System
.
currentTimeMillis
());
//TODO
}
@Test
public
void
execute
()
{
//TODO
}
@Test
public
void
addBatch
()
{
//TODO:
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setCharacterStream
()
throws
SQLException
{
pstmt_insert
.
setCharacterStream
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setRef
()
throws
SQLException
{
pstmt_insert
.
setRef
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBlob
()
throws
SQLException
{
pstmt_insert
.
setBlob
(
1
,
(
Blob
)
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setClob
()
throws
SQLException
{
pstmt_insert
.
setClob
(
1
,
(
Clob
)
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setArray
()
throws
SQLException
{
pstmt_insert
.
setArray
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getMetaData
()
throws
SQLException
{
pstmt_insert
.
getMetaData
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setURL
()
throws
SQLException
{
pstmt_insert
.
setURL
(
1
,
null
);
}
@Test
public
void
getParameterMetaData
()
throws
SQLException
{
ParameterMetaData
parameterMetaData
=
pstmt_insert
.
getParameterMetaData
();
Assert
.
assertNull
(
parameterMetaData
);
//TODO:
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setRowId
()
throws
SQLException
{
pstmt_insert
.
setRowId
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNString
()
throws
SQLException
{
pstmt_insert
.
setNString
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNCharacterStream
()
throws
SQLException
{
pstmt_insert
.
setNCharacterStream
(
1
,
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNClob
()
throws
SQLException
{
pstmt_insert
.
setNClob
(
1
,
(
NClob
)
null
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setSQLXML
()
throws
SQLException
{
pstmt_insert
.
setSQLXML
(
1
,
null
);
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS-RS://"
+
host
+
":6041/?user=root&password=taosdata"
);
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"drop database if exists test_pstmt"
);
stmt
.
execute
(
"create database if not exists test_pstmt"
);
stmt
.
execute
(
"use test_pstmt"
);
stmt
.
execute
(
"create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"
);
stmt
.
execute
(
"create table t1 using weather tags('beijing')"
);
}
pstmt_insert
=
conn
.
prepareStatement
(
sql_insert
);
pstmt_select
=
conn
.
prepareStatement
(
sql_select
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
static
void
afterClass
()
{
try
{
if
(
pstmt_insert
!=
null
)
pstmt_insert
.
close
();
if
(
pstmt_select
!=
null
)
pstmt_select
.
close
();
if
(
conn
!=
null
)
conn
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulStatementTest.java
0 → 100644
浏览文件 @
6fe5202a
package
com.taosdata.jdbc.rs
;
import
com.taosdata.jdbc.TSDBDriver
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.*
;
import
java.util.Properties
;
import
java.util.UUID
;
public
class
RestfulStatementTest
{
// private static final String host = "127.0.0.1";
private
static
final
String
host
=
"master"
;
private
static
Connection
conn
;
private
static
Statement
stmt
;
@Test
public
void
executeQuery
()
{
try
{
ResultSet
rs
=
stmt
.
executeQuery
(
"show databases"
);
Assert
.
assertNotNull
(
rs
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
i
)
+
": "
+
rs
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
}
rs
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
executeUpdate
()
{
final
String
dbName
=
(
"test_"
+
UUID
.
randomUUID
()).
replace
(
"-"
,
"_"
).
substring
(
0
,
32
);
try
{
int
affectRows
=
stmt
.
executeUpdate
(
"create database "
+
dbName
);
Assert
.
assertEquals
(
0
,
affectRows
);
affectRows
=
stmt
.
executeUpdate
(
"create table "
+
dbName
+
".weather(ts timestamp, temperature float) tags(loc nchar(64))"
);
Assert
.
assertEquals
(
0
,
affectRows
);
affectRows
=
stmt
.
executeUpdate
(
"insert into "
+
dbName
+
".t1 using "
+
dbName
+
".weather tags('北京') values(now, 22.33)"
);
Assert
.
assertEquals
(
1
,
affectRows
);
affectRows
=
stmt
.
executeUpdate
(
"drop database "
+
dbName
);
Assert
.
assertEquals
(
0
,
affectRows
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
close
()
{
// test in AfterClass method
}
@Test
public
void
getMaxFieldSize
()
throws
SQLException
{
Assert
.
assertEquals
(
16
*
1024
,
stmt
.
getMaxFieldSize
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setMaxFieldSize
()
throws
SQLException
{
stmt
.
setMaxFieldSize
(
0
);
stmt
.
setMaxFieldSize
(-
1
);
}
@Test
public
void
getMaxRows
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
stmt
.
getMaxRows
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setMaxRows
()
throws
SQLException
{
stmt
.
setMaxRows
(
0
);
stmt
.
setMaxRows
(-
1
);
}
@Test
public
void
setEscapeProcessing
()
throws
SQLException
{
stmt
.
setEscapeProcessing
(
true
);
stmt
.
setEscapeProcessing
(
false
);
}
@Test
public
void
getQueryTimeout
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
stmt
.
getQueryTimeout
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setQueryTimeout
()
throws
SQLException
{
stmt
.
setQueryTimeout
(
0
);
stmt
.
setQueryTimeout
(-
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
cancel
()
throws
SQLException
{
stmt
.
cancel
();
}
@Test
public
void
getWarnings
()
throws
SQLException
{
Assert
.
assertNull
(
stmt
.
getWarnings
());
}
@Test
public
void
clearWarnings
()
throws
SQLException
{
stmt
.
clearWarnings
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setCursorName
()
throws
SQLException
{
stmt
.
setCursorName
(
""
);
}
@Test
public
void
execute
()
{
final
String
dbName
=
(
"test_"
+
UUID
.
randomUUID
()).
replace
(
"-"
,
"_"
).
substring
(
0
,
32
);
try
{
boolean
isSelect
=
stmt
.
execute
(
"create database if not exists "
+
dbName
);
Assert
.
assertEquals
(
false
,
isSelect
);
int
affectedRows
=
stmt
.
getUpdateCount
();
Assert
.
assertEquals
(
0
,
affectedRows
);
isSelect
=
stmt
.
execute
(
"create table if not exists "
+
dbName
+
".weather(ts timestamp, temperature float) tags(loc nchar(64))"
);
Assert
.
assertEquals
(
false
,
isSelect
);
affectedRows
=
stmt
.
getUpdateCount
();
Assert
.
assertEquals
(
0
,
affectedRows
);
isSelect
=
stmt
.
execute
(
"insert into "
+
dbName
+
".t1 using "
+
dbName
+
".weather tags('北京') values(now, 22.33)"
);
Assert
.
assertEquals
(
false
,
isSelect
);
affectedRows
=
stmt
.
getUpdateCount
();
Assert
.
assertEquals
(
1
,
affectedRows
);
isSelect
=
stmt
.
execute
(
"select * from "
+
dbName
+
".weather"
);
Assert
.
assertEquals
(
true
,
isSelect
);
isSelect
=
stmt
.
execute
(
"drop database "
+
dbName
);
Assert
.
assertEquals
(
false
,
isSelect
);
affectedRows
=
stmt
.
getUpdateCount
();
Assert
.
assertEquals
(
0
,
affectedRows
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
getResultSet
()
{
final
String
dbName
=
(
"test_"
+
UUID
.
randomUUID
()).
replace
(
"-"
,
"_"
).
substring
(
0
,
32
);
try
{
boolean
isSelect
=
stmt
.
execute
(
"create database if not exists "
+
dbName
);
Assert
.
assertEquals
(
false
,
isSelect
);
int
affectedRows
=
stmt
.
getUpdateCount
();
Assert
.
assertEquals
(
0
,
affectedRows
);
isSelect
=
stmt
.
execute
(
"create table if not exists "
+
dbName
+
".weather(ts timestamp, temperature float) tags(loc nchar(64))"
);
Assert
.
assertEquals
(
false
,
isSelect
);
affectedRows
=
stmt
.
getUpdateCount
();
Assert
.
assertEquals
(
0
,
affectedRows
);
isSelect
=
stmt
.
execute
(
"insert into "
+
dbName
+
".t1 using "
+
dbName
+
".weather tags('北京') values(now, 22.33)"
);
Assert
.
assertEquals
(
false
,
isSelect
);
affectedRows
=
stmt
.
getUpdateCount
();
Assert
.
assertEquals
(
1
,
affectedRows
);
isSelect
=
stmt
.
execute
(
"select * from "
+
dbName
+
".weather"
);
Assert
.
assertEquals
(
true
,
isSelect
);
ResultSet
rs
=
stmt
.
getResultSet
();
Assert
.
assertNotNull
(
rs
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
Assert
.
assertEquals
(
3
,
meta
.
getColumnCount
());
int
count
=
0
;
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
i
)
+
": "
+
rs
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
count
++;
}
Assert
.
assertEquals
(
1
,
count
);
isSelect
=
stmt
.
execute
(
"drop database "
+
dbName
);
Assert
.
assertEquals
(
false
,
isSelect
);
affectedRows
=
stmt
.
getUpdateCount
();
Assert
.
assertEquals
(
0
,
affectedRows
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
getUpdateCount
()
{
// already test in execute method
}
@Test
public
void
getMoreResults
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
getMoreResults
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setFetchDirection
()
throws
SQLException
{
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_FORWARD
);
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_REVERSE
);
stmt
.
setFetchDirection
(
ResultSet
.
FETCH_UNKNOWN
);
stmt
.
setFetchDirection
(-
1
);
}
@Test
public
void
getFetchDirection
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
FETCH_FORWARD
,
stmt
.
getFetchDirection
());
}
@Test
(
expected
=
SQLException
.
class
)
public
void
setFetchSize
()
throws
SQLException
{
stmt
.
setFetchSize
(
0
);
stmt
.
setFetchSize
(-
1
);
}
@Test
public
void
getFetchSize
()
throws
SQLException
{
stmt
.
setFetchSize
(
0
);
Assert
.
assertEquals
(
0
,
stmt
.
getFetchSize
());
stmt
.
setFetchSize
(
0
);
}
@Test
public
void
getResultSetConcurrency
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
CONCUR_READ_ONLY
,
stmt
.
getResultSetConcurrency
());
}
@Test
public
void
getResultSetType
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
TYPE_FORWARD_ONLY
,
stmt
.
getResultSetType
());
}
@Test
public
void
addBatch
()
{
final
String
dbName
=
(
"test_"
+
UUID
.
randomUUID
()).
replace
(
"-"
,
"_"
).
substring
(
0
,
32
);
try
{
stmt
.
addBatch
(
"create database "
+
dbName
);
stmt
.
addBatch
(
"create table "
+
dbName
+
".weather(ts timestamp, temperature float) tags(loc nchar(64))"
);
stmt
.
addBatch
(
"insert into "
+
dbName
+
".t1 using "
+
dbName
+
".weather tags('北京') values(now, 22.33)"
);
stmt
.
addBatch
(
"select * from "
+
dbName
+
".weather"
);
stmt
.
addBatch
(
"drop database "
+
dbName
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
clearBatch
()
{
final
String
dbName
=
(
"test_"
+
UUID
.
randomUUID
()).
replace
(
"-"
,
"_"
).
substring
(
0
,
32
);
try
{
stmt
.
clearBatch
();
stmt
.
addBatch
(
"create database "
+
dbName
);
stmt
.
addBatch
(
"create table "
+
dbName
+
".weather(ts timestamp, temperature float) tags(loc nchar(64))"
);
stmt
.
addBatch
(
"insert into "
+
dbName
+
".t1 using "
+
dbName
+
".weather tags('北京') values(now, 22.33)"
);
stmt
.
addBatch
(
"select * from "
+
dbName
+
".weather"
);
stmt
.
addBatch
(
"drop database "
+
dbName
);
stmt
.
clearBatch
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
executeBatch
()
{
final
String
dbName
=
(
"test_"
+
UUID
.
randomUUID
()).
replace
(
"-"
,
"_"
).
substring
(
0
,
32
);
try
{
stmt
.
addBatch
(
"create database "
+
dbName
);
stmt
.
addBatch
(
"create table "
+
dbName
+
".weather(ts timestamp, temperature float) tags(loc nchar(64))"
);
stmt
.
addBatch
(
"insert into "
+
dbName
+
".t1 using "
+
dbName
+
".weather tags('北京') values(now, 22.33)"
);
stmt
.
addBatch
(
"select * from "
+
dbName
+
".weather"
);
stmt
.
addBatch
(
"drop database "
+
dbName
);
int
[]
results
=
stmt
.
executeBatch
();
Assert
.
assertEquals
(
0
,
results
[
0
]);
Assert
.
assertEquals
(
0
,
results
[
1
]);
Assert
.
assertEquals
(
1
,
results
[
2
]);
Assert
.
assertEquals
(
Statement
.
SUCCESS_NO_INFO
,
results
[
3
]);
Assert
.
assertEquals
(
0
,
results
[
4
]);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
getConnection
()
{
try
{
Connection
connection
=
stmt
.
getConnection
();
Assert
.
assertNotNull
(
connection
);
Assert
.
assertTrue
(
this
.
conn
==
connection
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testGetMoreResults
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
getMoreResults
(
Statement
.
CLOSE_CURRENT_RESULT
));
stmt
.
getMoreResults
(
Statement
.
KEEP_CURRENT_RESULT
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getGeneratedKeys
()
throws
SQLException
{
stmt
.
getGeneratedKeys
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate1
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
new
int
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecuteUpdate2
()
throws
SQLException
{
stmt
.
executeUpdate
(
""
,
new
String
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecute
()
throws
SQLException
{
stmt
.
execute
(
""
,
1
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecute1
()
throws
SQLException
{
stmt
.
execute
(
""
,
new
int
[]{});
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
testExecute2
()
throws
SQLException
{
stmt
.
execute
(
""
,
new
String
[]{});
}
@Test
public
void
getResultSetHoldability
()
throws
SQLException
{
Assert
.
assertEquals
(
ResultSet
.
HOLD_CURSORS_OVER_COMMIT
,
stmt
.
getResultSetHoldability
());
}
@Test
public
void
isClosed
()
{
try
{
Assert
.
assertEquals
(
false
,
stmt
.
isClosed
());
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
setPoolable
()
throws
SQLException
{
stmt
.
setPoolable
(
true
);
stmt
.
setPoolable
(
false
);
}
@Test
public
void
isPoolable
()
throws
SQLException
{
Assert
.
assertEquals
(
false
,
stmt
.
isPoolable
());
}
@Test
public
void
closeOnCompletion
()
throws
SQLException
{
stmt
.
closeOnCompletion
();
}
@Test
public
void
isCloseOnCompletion
()
throws
SQLException
{
Assert
.
assertFalse
(
stmt
.
isCloseOnCompletion
());
}
@Test
public
void
unwrap
()
throws
SQLException
{
RestfulStatement
unwrap
=
stmt
.
unwrap
(
RestfulStatement
.
class
);
Assert
.
assertNotNull
(
unwrap
);
}
@Test
public
void
isWrapperFor
()
throws
SQLException
{
Assert
.
assertTrue
(
stmt
.
isWrapperFor
(
RestfulStatement
.
class
));
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS-RS://"
+
host
+
":6041/?user=root&password=taosdata"
,
properties
);
stmt
=
conn
.
createStatement
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
static
void
afterClass
()
{
try
{
if
(
stmt
!=
null
)
stmt
.
close
();
if
(
conn
!=
null
)
conn
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
tests/examples/JDBC/JDBCDemo/pom.xml
浏览文件 @
6fe5202a
...
...
@@ -13,7 +13,7 @@
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.
18
</version>
<version>
2.0.
20
</version>
</dependency>
</dependencies>
...
...
tests/examples/JDBC/taosdemo/pom.xml
浏览文件 @
6fe5202a
...
...
@@ -67,7 +67,7 @@
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.
19
</version>
<version>
2.0.
20
</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
</dependency>
...
...
tests/examples/JDBC/taosdemo/readme.md
浏览文件 @
6fe5202a
```
cd tests/examples/JDBC/taosdemo
mvn clean package -Dmaven.test.skip=true
# 先建表,再插入的
java -jar target/taosdemo-2.0-jar-with-dependencies.jar -host [hostname] -database [database] -doCreateTable true -superTableSQL "create table weather(ts timestamp, f1 int) tags(t1 nchar(4))" -numOfTables 1000 -numOfRowsPerTable 100000000 -numOfThreadsForInsert 10 -numOfTablesPerSQL 10 -numOfValuesPerSQL 100
# 不建表,直接插入的
java -jar target/taosdemo-2.0-jar-with-dependencies.jar -host [hostname] -database [database] -doCreateTable false -superTableSQL "create table weather(ts timestamp, f1 int) tags(t1 nchar(4))" -numOfTables 1000 -numOfRowsPerTable 100000000 -numOfThreadsForInsert 10 -numOfTablesPerSQL 10 -numOfValuesPerSQL 100
```
需求:
1.
可以读lowa的配置文件
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
浏览文件 @
6fe5202a
...
...
@@ -35,7 +35,7 @@ public class TaosDemoApplication {
final
DatabaseService
databaseService
=
new
DatabaseService
(
dataSource
);
final
SuperTableService
superTableService
=
new
SuperTableService
(
dataSource
);
final
SubTableService
subTableService
=
new
SubTableService
(
dataSource
);
final
QueryService
queryService
=
new
QueryService
(
dataSource
);
// 创建数据库
long
start
=
System
.
currentTimeMillis
();
Map
<
String
,
String
>
databaseParam
=
new
HashMap
<>();
...
...
tests/examples/JDBC/taosdemo/src/main/resources/application.properties
浏览文件 @
6fe5202a
jdbc.driver
=
com.taosdata.jdbc.rs.RestfulDriver
#jdbc.driver=com.taosdata.jdbc.TSDBDriver
hikari.maximum-pool-size
=
1
hikari.minimum-idle
=
1
hikari.maximum-pool-size
=
20
hikari.minimum-idle
=
20
hikari.max-lifetime
=
0
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录