Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e0b0a8e4
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e0b0a8e4
编写于
2月 24, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2868]<feature>: JDBC-Restful supported PreparedStatement
上级
2f80bac5
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
726 addition
and
193 deletion
+726
-193
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
...ector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
+1
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
+2
-2
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/RestfulPreparedStatement.java
...n/java/com/taosdata/jdbc/rs/RestfulPreparedStatement.java
+465
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
.../src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
+1
-1
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
+4
-0
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
+1
-0
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
浏览文件 @
e0b0a8e4
...
...
@@ -22,7 +22,7 @@ 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_
BOUNDARY
,
"parameter index out of range"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_
RANGE
,
"parameter index out of range"
);
/**************************************************/
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"unknown error"
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
浏览文件 @
e0b0a8e4
...
...
@@ -16,7 +16,7 @@ public class TSDBErrorNumbers {
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_PARAMETER_INDEX_OUT_
BOUNDARY
=
0x2313
;
// parameter index out of range
public
static
final
int
ERROR_PARAMETER_INDEX_OUT_
RANGE
=
0x2313
;
// parameter index out of range
public
static
final
int
ERROR_UNKNOWN
=
0x2350
;
//unknown error
...
...
@@ -46,7 +46,7 @@ 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_
BOUNDARY
);
errorNumbers
.
add
(
ERROR_PARAMETER_INDEX_OUT_
RANGE
);
/*****************************************************/
errorNumbers
.
add
(
ERROR_SUBSCRIBE_FAILED
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java
浏览文件 @
e0b0a8e4
...
...
@@ -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/RestfulPreparedStatement.java
0 → 100644
浏览文件 @
e0b0a8e4
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/RestfulStatement.java
浏览文件 @
e0b0a8e4
...
...
@@ -30,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"
))
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java
已删除
100644 → 0
浏览文件 @
2f80bac5
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
浏览文件 @
e0b0a8e4
...
...
@@ -59,18 +59,22 @@ public class TSDBPreparedStatementTest {
@Test
public
void
setShort
()
{
}
@Test
public
void
setInt
()
{
}
@Test
public
void
setLong
()
{
}
@Test
public
void
setFloat
()
{
}
@Test
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java
0 → 100644
浏览文件 @
e0b0a8e4
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
浏览文件 @
e0b0a8e4
...
...
@@ -414,4 +414,5 @@ public class RestfulStatementTest {
e
.
printStackTrace
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录