Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
哥们要飞
TDengine
提交
9e3196c4
T
TDengine
项目概览
哥们要飞
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9e3196c4
编写于
1月 27, 2021
作者:
H
huili
提交者:
GitHub
1月 27, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5043 from taosdata/hotfix/TD-2672
Hotfix/td 2672
上级
142ca8ee
9bb35349
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
514 addition
and
639 deletion
+514
-639
src/connector/jdbc/pom.xml
src/connector/jdbc/pom.xml
+1
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
+1
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
...rc/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+1
-3
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+13
-2
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
.../src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
+23
-24
src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java
...nector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java
+0
-33
src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java
...jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java
+0
-115
src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java
...rc/test/java/com/taosdata/jdbc/PreparedStatementTest.java
+43
-58
src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java
+39
-48
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
+31
-38
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
...ctor/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
+1
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
+46
-119
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
+33
-26
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
...test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
+31
-31
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
.../jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
+16
-52
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
...est/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
+186
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java
...rc/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java
+49
-38
src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java
.../jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java
+0
-47
src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java
.../java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java
+0
-4
未找到文件。
src/connector/jdbc/pom.xml
浏览文件 @
9e3196c4
...
...
@@ -126,7 +126,7 @@
<include>
**/*Test.java
</include>
</includes>
<excludes>
<exclude>
**/
BatchInsert
Test.java
</exclude>
<exclude>
**/
AppMemoryLeak
Test.java
</exclude>
<exclude>
**/FailOverTest.java
</exclude>
</excludes>
<testFailureIgnore>
true
</testFailureIgnore>
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
浏览文件 @
9e3196c4
...
...
@@ -19,6 +19,7 @@ import java.util.Map;
public
abstract
class
TSDBConstants
{
public
static
final
String
STATEMENT_CLOSED
=
"Statement already closed."
;
public
static
final
String
DEFAULT_PORT
=
"6200"
;
public
static
final
String
UNSUPPORT_METHOD_EXCEPTIONZ_MSG
=
"this operation is NOT supported currently!"
;
public
static
final
String
INVALID_VARIABLES
=
"invalid variables"
;
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
浏览文件 @
9e3196c4
...
...
@@ -100,7 +100,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
* order to process those supported SQLs.
*/
private
void
preprocessSql
()
{
/***** For processing some of Spark SQLs*****/
// should replace it first
this
.
rawSql
=
this
.
rawSql
.
replaceAll
(
"or (.*) is null"
,
""
);
...
...
@@ -149,7 +148,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
rawSql
=
rawSql
.
replace
(
matcher
.
group
(
1
),
tableFullName
);
}
/***** for inner queries *****/
}
/**
...
...
@@ -196,7 +194,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public
void
setNull
(
int
parameterIndex
,
int
sqlType
)
throws
SQLException
{
setObject
(
parameterIndex
,
new
String
(
"NULL"
)
);
setObject
(
parameterIndex
,
"NULL"
);
}
@Override
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
9e3196c4
...
...
@@ -52,12 +52,18 @@ public class TSDBStatement implements Statement {
this
.
isClosed
=
false
;
}
@Override
public
<
T
>
T
unwrap
(
Class
<
T
>
iface
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORT_METHOD_EXCEPTIONZ_MSG
);
try
{
return
iface
.
cast
(
this
);
}
catch
(
ClassCastException
cce
)
{
throw
new
SQLException
(
"Unable to unwrap to "
+
iface
.
toString
());
}
}
@Override
public
boolean
isWrapperFor
(
Class
<?>
iface
)
throws
SQLException
{
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORT_METHOD_EXCEPTIONZ_MSG
);
return
iface
.
isInstance
(
this
);
}
public
ResultSet
executeQuery
(
String
sql
)
throws
SQLException
{
...
...
@@ -130,10 +136,15 @@ public class TSDBStatement implements Statement {
}
public
void
setMaxFieldSize
(
int
max
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORT_METHOD_EXCEPTIONZ_MSG
);
}
public
int
getMaxRows
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
// always set maxRows to zero, meaning unlimitted rows in a resultSet
return
0
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
浏览文件 @
9e3196c4
...
...
@@ -14,7 +14,6 @@ import java.util.stream.Collectors;
public
class
RestfulStatement
implements
Statement
{
private
static
final
String
STATEMENT_CLOSED
=
"Statement already closed."
;
private
boolean
closed
;
private
String
database
;
private
final
RestfulConnection
conn
;
...
...
@@ -108,14 +107,14 @@ public class RestfulStatement implements Statement {
@Override
public
int
getMaxFieldSize
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
TSDBConstants
.
maxFieldSize
;
}
@Override
public
void
setMaxFieldSize
(
int
max
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
if
(
max
<
0
)
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
// nothing to do
...
...
@@ -124,14 +123,14 @@ public class RestfulStatement implements Statement {
@Override
public
int
getMaxRows
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
0
;
}
@Override
public
void
setMaxRows
(
int
max
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
if
(
max
<
0
)
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
// nothing to do
...
...
@@ -140,20 +139,20 @@ public class RestfulStatement implements Statement {
@Override
public
void
setEscapeProcessing
(
boolean
enable
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
RestfulStatement
.
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
}
@Override
public
int
getQueryTimeout
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
0
;
}
@Override
public
void
setQueryTimeout
(
int
seconds
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
if
(
seconds
<
0
)
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
}
...
...
@@ -166,7 +165,7 @@ public class RestfulStatement implements Statement {
@Override
public
SQLWarning
getWarnings
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
null
;
}
...
...
@@ -174,13 +173,13 @@ public class RestfulStatement implements Statement {
public
void
clearWarnings
()
throws
SQLException
{
// nothing to do
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
}
@Override
public
void
setCursorName
(
String
name
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
RestfulStatement
.
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
UNSUPPORT_METHOD_EXCEPTIONZ_MSG
);
}
...
...
@@ -260,7 +259,7 @@ public class RestfulStatement implements Statement {
@Override
public
ResultSet
getResultSet
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
resultSet
;
}
...
...
@@ -292,7 +291,7 @@ public class RestfulStatement implements Statement {
@Override
public
void
setFetchSize
(
int
rows
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
if
(
rows
<
0
)
throw
new
SQLException
(
TSDBConstants
.
INVALID_VARIABLES
);
//nothing to do
...
...
@@ -301,28 +300,28 @@ public class RestfulStatement implements Statement {
@Override
public
int
getFetchSize
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
0
;
}
@Override
public
int
getResultSetConcurrency
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
this
.
resultSet
.
getConcurrency
();
}
@Override
public
int
getResultSetType
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
this
.
resultSet
.
getType
();
}
@Override
public
void
addBatch
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
//TODO:
}
...
...
@@ -340,14 +339,14 @@ public class RestfulStatement implements Statement {
@Override
public
Connection
getConnection
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
this
.
conn
;
}
@Override
public
boolean
getMoreResults
(
int
current
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
if
(
resultSet
==
null
)
return
false
;
...
...
@@ -405,7 +404,7 @@ public class RestfulStatement implements Statement {
@Override
public
int
getResultSetHoldability
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
this
.
resultSet
.
getHoldability
();
}
...
...
@@ -417,28 +416,28 @@ public class RestfulStatement implements Statement {
@Override
public
void
setPoolable
(
boolean
poolable
)
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
//nothing to do
}
@Override
public
boolean
isPoolable
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
false
;
}
@Override
public
void
closeOnCompletion
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
this
.
closeOnCompletion
=
true
;
}
@Override
public
boolean
isCloseOnCompletion
()
throws
SQLException
{
if
(
isClosed
())
throw
new
SQLException
(
STATEMENT_CLOSED
);
throw
new
SQLException
(
TSDBConstants
.
STATEMENT_CLOSED
);
return
this
.
closeOnCompletion
;
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java
已删除
100644 → 0
浏览文件 @
142ca8ee
package
com.taosdata.jdbc
;
import
com.taosdata.jdbc.utils.TDNodes
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
public
abstract
class
BaseTest
{
private
static
boolean
testCluster
=
false
;
private
static
TDNodes
nodes
=
new
TDNodes
();
@BeforeClass
public
static
void
setupEnv
()
{
try
{
if
(
nodes
.
getTDNode
(
1
).
getTaosdPid
()
!=
null
)
{
System
.
out
.
println
(
"Kill taosd before running JDBC test"
);
nodes
.
getTDNode
(
1
).
setRunning
(
1
);
nodes
.
stop
(
1
);
}
nodes
.
setTestCluster
(
testCluster
);
nodes
.
deploy
(
1
);
nodes
.
start
(
1
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
static
void
cleanUpEnv
()
{
nodes
.
stop
(
1
);
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java
已删除
100644 → 0
浏览文件 @
142ca8ee
package
com.taosdata.jdbc
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.*
;
import
java.util.Properties
;
import
java.util.Random
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
BatchInsertTest
{
private
Connection
connection
;
private
static
String
dbName
=
"test"
;
private
static
String
stbName
=
"meters"
;
private
static
String
host
=
"127.0.0.1"
;
private
static
int
numOfTables
=
30
;
private
static
int
numOfRecordsPerTable
=
1000
;
private
static
long
ts
=
1496732686000
l
;
private
static
String
tablePrefix
=
"t"
;
@Before
public
void
createDatabase
()
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
);
Statement
stmt
=
connection
.
createStatement
();
stmt
.
execute
(
"drop database if exists "
+
dbName
);
stmt
.
execute
(
"create database if not exists "
+
dbName
);
stmt
.
execute
(
"use "
+
dbName
);
String
createTableSql
=
"create table "
+
stbName
+
"(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))"
;
stmt
.
execute
(
createTableSql
);
for
(
int
i
=
0
;
i
<
numOfTables
;
i
++)
{
String
loc
=
i
%
2
==
0
?
"beijing"
:
"shanghai"
;
String
createSubTalbesSql
=
"create table "
+
tablePrefix
+
i
+
" using "
+
stbName
+
" tags("
+
i
+
", '"
+
loc
+
"')"
;
stmt
.
execute
(
createSubTalbesSql
);
}
stmt
.
close
();
}
@Test
public
void
testBatchInsert
()
throws
SQLException
{
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
numOfTables
);
for
(
int
i
=
0
;
i
<
numOfTables
;
i
++)
{
final
int
index
=
i
;
executorService
.
execute
(()
->
{
try
{
long
startTime
=
System
.
currentTimeMillis
();
Statement
statement
=
connection
.
createStatement
();
// get statement
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"INSERT INTO "
+
tablePrefix
+
index
+
" VALUES"
);
Random
rand
=
new
Random
();
for
(
int
j
=
1
;
j
<=
numOfRecordsPerTable
;
j
++)
{
sb
.
append
(
"("
+
(
ts
+
j
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
")"
);
}
statement
.
addBatch
(
sb
.
toString
());
statement
.
executeBatch
();
long
endTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"Thread "
+
index
+
" takes "
+
(
endTime
-
startTime
)
+
" microseconds"
);
connection
.
commit
();
statement
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
});
}
executorService
.
shutdown
();
try
{
executorService
.
awaitTermination
(
Long
.
MAX_VALUE
,
TimeUnit
.
NANOSECONDS
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Statement
statement
=
connection
.
createStatement
();
ResultSet
rs
=
statement
.
executeQuery
(
"select * from meters"
);
int
num
=
0
;
while
(
rs
.
next
())
{
num
++;
}
assertEquals
(
num
,
numOfTables
*
numOfRecordsPerTable
);
rs
.
close
();
}
@After
public
void
close
()
{
try
{
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java
浏览文件 @
9e3196c4
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.FixMethodOrder
;
import
org.junit.Test
;
import
org.junit.*
;
import
org.junit.runners.MethodSorters
;
import
java.sql.*
;
import
java.util.Properties
;
...
...
@@ -11,14 +9,13 @@ import java.util.Properties;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@FixMethodOrder
()
public
class
PreparedStatementTest
extends
BaseTest
{
static
Connection
connection
=
null
;
static
PreparedStatement
statement
=
null
;
@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"
;
static
ResultSet
resSet
=
null
;
@BeforeClass
public
static
void
createConnection
()
throws
SQLException
{
...
...
@@ -28,19 +25,16 @@ public class PreparedStatementTest extends BaseTest {
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
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
createTableAndQuery
()
throws
SQLException
{
public
void
c
ase001_c
reateTableAndQuery
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
...
...
@@ -48,141 +42,132 @@ public class PreparedStatementTest extends BaseTest {
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
testPreparedStatement
()
throws
SQLException
{
public
void
case002_
testPreparedStatement
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
()
+
20000
;
PreparedStatement
saveStatement
=
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", 1)"
);
PreparedStatement
saveStatement
=
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", 1)"
);
int
affectedRows
=
saveStatement
.
executeUpdate
();
assertTrue
(
1
==
affectedRows
);
saveStatement
.
close
();
}
@Test
public
void
testSavedPreparedStatement
()
throws
SQLException
{
public
void
case003_
testSavedPreparedStatement
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
();
TSDBPreparedStatement
saveStatement
=
(
TSDBPreparedStatement
)
connection
.
prepareStatement
(
"insert into "
+
dbName
+
"."
+
tName
+
" values (?, ?)"
);
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
testUnsupport
()
{
// if(null == resSet) {
// return;
// }
TSDBPreparedStatement
tsdbStatement
=
(
TSDBPreparedStatement
)
statement
;
try
{
tsdbStatement
.
unwrap
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
isWrapperFor
(
null
);
}
catch
(
SQLException
e
)
{
}
public
void
case004_testUnsupport
()
throws
SQLException
{
Assert
.
assertNotNull
(
statement
.
unwrap
(
TSDBPreparedStatement
.
class
));
Assert
.
assertTrue
(
statement
.
isWrapperFor
(
TSDBPreparedStatement
.
class
));
try
{
tsdbS
tatement
.
getMaxFieldSize
();
s
tatement
.
getMaxFieldSize
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
setMaxFieldSize
(
0
);
s
tatement
.
setMaxFieldSize
(
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
setEscapeProcessing
(
true
);
s
tatement
.
setEscapeProcessing
(
true
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
cancel
();
s
tatement
.
cancel
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getWarnings
();
s
tatement
.
getWarnings
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
clearWarnings
();
s
tatement
.
clearWarnings
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
setCursorName
(
null
);
s
tatement
.
setCursorName
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getMoreResults
();
s
tatement
.
getMoreResults
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
setFetchDirection
(
0
);
s
tatement
.
setFetchDirection
(
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getFetchDirection
();
s
tatement
.
getFetchDirection
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getResultSetConcurrency
();
s
tatement
.
getResultSetConcurrency
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getResultSetType
();
s
tatement
.
getResultSetType
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getConnection
();
s
tatement
.
getConnection
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getMoreResults
();
s
tatement
.
getMoreResults
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getGeneratedKeys
();
s
tatement
.
getGeneratedKeys
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
executeUpdate
(
null
,
0
);
s
tatement
.
executeUpdate
(
null
,
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
executeUpdate
(
null
,
new
int
[]{
0
});
s
tatement
.
executeUpdate
(
null
,
new
int
[]{
0
});
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
executeUpdate
(
null
,
new
String
[]{
"str1"
,
"str2"
});
s
tatement
.
executeUpdate
(
null
,
new
String
[]{
"str1"
,
"str2"
});
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
getResultSetHoldability
();
s
tatement
.
getResultSetHoldability
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
setPoolable
(
true
);
s
tatement
.
setPoolable
(
true
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
isPoolable
();
s
tatement
.
isPoolable
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
closeOnCompletion
();
s
tatement
.
closeOnCompletion
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbS
tatement
.
isCloseOnCompletion
();
s
tatement
.
isCloseOnCompletion
();
}
catch
(
SQLException
e
)
{
}
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java
浏览文件 @
9e3196c4
...
...
@@ -6,76 +6,67 @@ import org.junit.Test;
import
java.sql.*
;
import
java.util.Properties
;
import
java.util.Random
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.util.Properties
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.*
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
QueryDataTest
extends
BaseTest
{
public
class
QueryDataTest
{
static
Connection
connection
=
null
;
static
Statement
statement
=
null
;
static
Connection
connection
;
static
Statement
statement
;
static
String
dbName
=
"test"
;
static
String
stbName
=
"meters"
;
static
String
host
=
"localhost"
;
static
int
numOfTables
=
30
;
final
static
int
numOfRecordsPerTable
=
1000
;
static
long
ts
=
1496732686000
l
;
final
static
String
tablePrefix
=
"t"
;
static
String
host
=
"127.0.0.1"
;
@Before
public
void
createDatabase
()
throws
SQLException
{
public
void
createDatabase
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
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
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"use "
+
dbName
);
String
createTableSql
=
"create table "
+
stbName
+
"(ts timestamp, name binary(64))"
;
statement
.
executeUpdate
(
createTableSql
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
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
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"use "
+
dbName
);
String
createTableSql
=
"create table "
+
stbName
+
"(ts timestamp, name binary(6))"
;
statement
.
executeUpdate
(
createTableSql
);
}
@Test
public
void
testQueryBinaryData
()
throws
SQLException
{
String
insertSql
=
"insert into "
+
stbName
+
" values(now, 'taosda')"
;
System
.
out
.
println
(
insertSql
);
@Test
public
void
testQueryBinaryData
()
throws
SQLException
{
String
insertSql
=
"insert into "
+
stbName
+
" values(now, 'taosdata')"
;
System
.
out
.
println
(
insertSql
);
statement
.
executeUpdate
(
insertSql
);
String
querySql
=
"select * from "
+
stbName
;
ResultSet
rs
=
statement
.
executeQuery
(
querySql
);
ResultSet
rs
=
statement
.
executeQuery
(
querySql
);
while
(
rs
.
next
())
{
String
name
=
rs
.
getString
(
2
)
+
"001"
;
while
(
rs
.
next
())
{
String
name
=
rs
.
getString
(
2
);
System
.
out
.
println
(
"name = "
+
name
);
assertEquals
(
name
,
"taosda001"
);
assertEquals
(
"taosdata"
,
name
);
}
rs
.
close
();
rs
.
close
();
}
@After
public
void
close
()
throws
Exception
{
statement
.
close
();
connection
.
close
();
Thread
.
sleep
(
10
);
public
void
close
()
{
try
{
if
(
statement
!=
null
)
statement
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
浏览文件 @
9e3196c4
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
...
...
@@ -13,42 +14,37 @@ import java.util.Properties;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
ResultSetTest
extends
BaseTest
{
static
Connection
connection
=
null
;
static
Statement
statement
=
null
;
public
class
ResultSetTest
{
static
Connection
connection
;
static
Statement
statement
;
static
String
dbName
=
"test"
;
static
String
tName
=
"t0"
;
static
String
host
=
"localhost"
;
static
ResultSet
resSet
=
null
;
static
ResultSet
resSet
;
@BeforeClass
public
static
void
createDatabaseAndTable
()
throws
SQLException
{
public
static
void
createDatabaseAndTable
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
execute
(
"use "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
" (ts timestamp, k1 int, k2 bigint, k3 float, k4 double, k5 binary(30), k6 smallint, k7 bool, k8 nchar(20))"
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
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
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
" (ts timestamp, k1 int, k2 bigint, k3 float, k4 double, k5 binary(30), k6 smallint, k7 bool, k8 nchar(20))"
);
statement
.
executeQuery
(
"use "
+
dbName
);
}
@Test
public
void
testResultSet
()
{
String
sql
=
null
;
String
sql
;
long
ts
=
1496732686000
l
;
int
v1
=
2147483600
;
long
v2
=
ts
+
1000
;
...
...
@@ -119,16 +115,8 @@ public class ResultSetTest extends BaseTest {
public
void
testUnsupport
()
throws
SQLException
{
statement
.
executeQuery
(
"show databases"
);
resSet
=
statement
.
getResultSet
();
try
{
resSet
.
unwrap
(
null
);
}
catch
(
SQLException
e
)
{
assertTrue
(
e
.
getMessage
().
contains
(
"this operation is NOT supported currently!"
));
}
try
{
resSet
.
isWrapperFor
(
null
);
}
catch
(
SQLException
e
)
{
assertTrue
(
e
.
getMessage
().
contains
(
"this operation is NOT supported currently!"
));
}
Assert
.
assertNotNull
(
resSet
.
unwrap
(
TSDBResultSet
.
class
));
Assert
.
assertTrue
(
resSet
.
isWrapperFor
(
TSDBResultSet
.
class
));
try
{
resSet
.
getAsciiStream
(
0
);
}
catch
(
SQLException
e
)
{
...
...
@@ -815,13 +803,18 @@ public class ResultSetTest extends BaseTest {
assertEquals
(
res
.
length
,
2
);
statement
.
clearBatch
();
}
@AfterClass
public
static
void
close
()
throws
Exception
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
Thread
.
sleep
(
10
);
@AfterClass
public
static
void
close
()
{
try
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
if
(
statement
!=
null
)
statement
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
浏览文件 @
9e3196c4
...
...
@@ -29,6 +29,7 @@ public class StableTest {
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
,
properties
);
Statement
statement
=
connection
.
createStatement
();
statement
.
execute
(
"drop database if exists "
+
dbName
);
statement
.
execute
(
"create database if not exists "
+
dbName
);
statement
.
execute
(
"use "
+
dbName
);
statement
.
close
();
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
浏览文件 @
9e3196c4
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
...
...
@@ -16,23 +17,22 @@ public class StatementTest {
static
String
dbName
=
"test"
;
static
String
tName
=
"t0"
;
static
String
host
=
"localhost"
;
static
ResultSet
resSet
=
null
;
@BeforeClass
public
static
void
createConnection
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
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/?user=root&password=taosdata"
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
}
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/?user=root&password=taosdata"
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
}
@Test
...
...
@@ -49,7 +49,6 @@ public class StatementTest {
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
...
...
@@ -67,118 +66,46 @@ public class StatementTest {
assertEquals
(
false
,
isClosed
);
}
@Test
public
void
testUnsupport
()
{
TSDBStatement
tsdbStatement
=
(
TSDBStatement
)
statement
;
try
{
tsdbStatement
.
unwrap
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
isWrapperFor
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getMaxFieldSize
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setMaxFieldSize
(
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setEscapeProcessing
(
true
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
cancel
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getWarnings
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
clearWarnings
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setCursorName
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getMoreResults
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setFetchDirection
(
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getFetchDirection
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getResultSetConcurrency
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getResultSetType
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getConnection
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getMoreResults
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getGeneratedKeys
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
executeUpdate
(
null
,
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
executeUpdate
(
null
,
new
int
[]{
0
});
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
executeUpdate
(
null
,
new
String
[]{
"str1"
,
"str2"
});
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getResultSetHoldability
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setPoolable
(
true
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
isPoolable
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
closeOnCompletion
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
isCloseOnCompletion
();
}
catch
(
SQLException
e
)
{
}
@Test
(
expected
=
SQLException
.
class
)
public
void
testUnsupport
()
throws
SQLException
{
Assert
.
assertNotNull
(
statement
.
unwrap
(
TSDBStatement
.
class
));
Assert
.
assertTrue
(
statement
.
isWrapperFor
(
TSDBStatement
.
class
));
statement
.
getMaxFieldSize
();
statement
.
setMaxFieldSize
(
0
);
statement
.
setEscapeProcessing
(
true
);
statement
.
cancel
();
statement
.
getWarnings
();
statement
.
clearWarnings
();
statement
.
setCursorName
(
null
);
statement
.
getMoreResults
();
statement
.
setFetchDirection
(
0
);
statement
.
getFetchDirection
();
statement
.
getResultSetConcurrency
();
statement
.
getResultSetType
();
statement
.
getConnection
();
statement
.
getMoreResults
();
statement
.
getGeneratedKeys
();
statement
.
executeUpdate
(
null
,
0
);
statement
.
executeUpdate
(
null
,
new
int
[]{
0
});
statement
.
executeUpdate
(
null
,
new
String
[]{
"str1"
,
"str2"
});
statement
.
getResultSetHoldability
();
statement
.
setPoolable
(
true
);
statement
.
isPoolable
();
statement
.
closeOnCompletion
();
statement
.
isCloseOnCompletion
();
}
@AfterClass
public
static
void
close
()
throws
Exception
{
if
(!
statement
.
isClosed
())
{
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
statement
.
close
();
connection
.
close
();
Thread
.
sleep
(
10
);
public
static
void
close
()
{
try
{
statement
.
execute
(
"drop database if exists "
+
dbName
);
if
(
statement
!=
null
)
statement
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
浏览文件 @
9e3196c4
...
...
@@ -10,36 +10,37 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.util.Properties
;
public
class
SubscribeTest
extends
BaseTest
{
Connection
connection
=
null
;
Statement
statement
=
null
;
public
class
SubscribeTest
{
Connection
connection
;
Statement
statement
;
String
dbName
=
"test"
;
String
tName
=
"t0"
;
String
host
=
"localhost"
;
String
topic
=
"test"
;
@Before
public
void
createDatabase
()
throws
SQLException
{
public
void
createDatabase
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
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
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
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
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
" (ts timestamp, k int, v int)"
);
long
ts
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
ts
+=
i
;
String
sql
=
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", "
+
(
100
+
i
)
+
", "
+
i
+
")"
;
statement
.
executeUpdate
(
sql
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
" (ts timestamp, k int, v int)"
);
long
ts
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
ts
+=
i
;
String
sql
=
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", "
+
(
100
+
i
)
+
", "
+
i
+
")"
;
statement
.
executeUpdate
(
sql
);
}
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
return
;
}
}
...
...
@@ -79,10 +80,16 @@ public class SubscribeTest extends BaseTest {
}
@After
public
void
close
()
throws
Exception
{
statement
.
executeQuery
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
Thread
.
sleep
(
10
);
public
void
close
()
{
try
{
statement
.
executeQuery
(
"drop database "
+
dbName
);
if
(
statement
!=
null
)
statement
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
浏览文件 @
9e3196c4
...
...
@@ -6,37 +6,9 @@ import java.sql.*;
import
java.util.Properties
;
public
class
TSDBDatabaseMetaDataTest
{
private
TSDBDatabaseMetaData
metaData
;
private
static
final
String
host
=
"127.0.0.1"
;
private
Connection
connection
;
@BeforeClass
public
void
before
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
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
+
":6030/?user=root&password=taosdata"
,
properties
);
metaData
=
connection
.
getMetaData
().
unwrap
(
TSDBDatabaseMetaData
.
class
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
void
after
()
{
try
{
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
private
static
Connection
connection
;
private
static
TSDBDatabaseMetaData
metaData
;
@Test
public
void
unwrap
()
throws
SQLException
{
...
...
@@ -61,7 +33,7 @@ public class TSDBDatabaseMetaDataTest {
@Test
public
void
getURL
()
throws
SQLException
{
Assert
.
assertEquals
(
"jdbc:TAOS://
localhost
:6030/?user=root&password=taosdata"
,
metaData
.
getURL
());
Assert
.
assertEquals
(
"jdbc:TAOS://
"
+
host
+
"
:6030/?user=root&password=taosdata"
,
metaData
.
getURL
());
}
@Test
...
...
@@ -975,4 +947,32 @@ public class TSDBDatabaseMetaDataTest {
public
void
generatedKeyAlwaysReturned
()
throws
SQLException
{
Assert
.
assertFalse
(
metaData
.
generatedKeyAlwaysReturned
());
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
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
+
":6030/?user=root&password=taosdata"
,
properties
);
metaData
=
connection
.
getMetaData
().
unwrap
(
TSDBDatabaseMetaData
.
class
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
static
void
afterClass
()
{
try
{
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
浏览文件 @
9e3196c4
...
...
@@ -3,9 +3,6 @@ package com.taosdata.jdbc;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.sql.*
;
import
java.util.Properties
;
...
...
@@ -27,54 +24,15 @@ public class TSDBDriverTest {
"jdbc:TAOS://:/test"
,
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
};
private
static
boolean
islibLoaded
=
false
;
private
static
boolean
isTaosdActived
;
private
Connection
conn
;
@BeforeClass
public
static
void
before
()
{
String
osName
=
System
.
getProperty
(
"os.name"
).
toLowerCase
();
if
(!
osName
.
equals
(
"linux"
))
return
;
// try to load taos lib
try
{
System
.
loadLibrary
(
"taos"
);
islibLoaded
=
true
;
}
catch
(
UnsatisfiedLinkError
error
)
{
System
.
out
.
println
(
"load tdengine lib failed."
);
error
.
printStackTrace
();
}
// check taosd is activated
try
{
String
[]
cmd
=
{
"/bin/bash"
,
"-c"
,
"ps -ef | grep taosd | grep -v \"grep\""
};
Process
exec
=
Runtime
.
getRuntime
().
exec
(
cmd
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
exec
.
getInputStream
()));
int
lineCnt
=
0
;
while
(
reader
.
readLine
()
!=
null
)
{
lineCnt
++;
}
if
(
lineCnt
>
0
)
isTaosdActived
=
true
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testConnectWithJdbcURL
()
{
final
String
url
=
"jdbc:TAOS://localhost:6030/log?user=root&password=taosdata"
;
try
{
if
(
islibLoaded
&&
isTaosdActived
)
{
conn
=
DriverManager
.
getConnection
(
url
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
conn
=
DriverManager
.
getConnection
(
url
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
fail
(
"failure - should not throw Exception"
);
...
...
@@ -89,10 +47,8 @@ public class TSDBDriverTest {
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
try
{
if
(
islibLoaded
&&
isTaosdActived
)
{
conn
=
DriverManager
.
getConnection
(
jdbcUrl
,
connProps
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
conn
=
DriverManager
.
getConnection
(
jdbcUrl
,
connProps
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
fail
(
"failure - should not throw Exception"
);
...
...
@@ -107,10 +63,8 @@ public class TSDBDriverTest {
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
try
{
if
(
islibLoaded
&&
isTaosdActived
)
{
conn
=
DriverManager
.
getConnection
(
jdbcUrl
,
connProps
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
conn
=
DriverManager
.
getConnection
(
jdbcUrl
,
connProps
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
fail
(
"failure - should not throw Exception"
);
...
...
@@ -207,4 +161,14 @@ public class TSDBDriverTest {
assertNull
(
"failure - getParentLogger should be be null"
,
new
TSDBDriver
().
getParentLogger
());
}
@BeforeClass
public
static
void
before
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
0 → 100644
浏览文件 @
9e3196c4
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
public
class
TSDBPreparedStatementTest
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
Connection
conn
;
@Test
public
void
executeQuery
()
{
}
@Test
public
void
executeUpdate
()
{
}
@Test
public
void
setNull
()
{
}
@Test
public
void
setBoolean
()
{
}
@Test
public
void
setByte
()
{
}
@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
public
void
setString
()
{
}
@Test
public
void
setBytes
()
{
}
@Test
public
void
setDate
()
{
}
@Test
public
void
setTime
()
{
}
@Test
public
void
setTimestamp
()
{
}
@Test
public
void
setAsciiStream
()
{
}
@Test
public
void
setUnicodeStream
()
{
}
@Test
public
void
setBinaryStream
()
{
}
@Test
public
void
clearParameters
()
{
}
@Test
public
void
setObject
()
{
}
@Test
public
void
execute
()
{
}
@Test
public
void
addBatch
()
{
}
@Test
public
void
setCharacterStream
()
{
}
@Test
public
void
setRef
()
{
}
@Test
public
void
setBlob
()
{
}
@Test
public
void
setClob
()
{
}
@Test
public
void
setArray
()
{
}
@Test
public
void
getMetaData
()
{
}
@Test
public
void
setURL
()
{
}
@Test
public
void
getParameterMetaData
()
{
}
@Test
public
void
setRowId
()
{
}
@Test
public
void
setNString
()
{
}
@Test
public
void
setNCharacterStream
()
{
}
@Test
public
void
setNClob
()
{
}
@Test
public
void
setSQLXML
()
{
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
public
static
void
afterClass
()
{
try
{
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/cases/BatchInsertTest.java
浏览文件 @
9e3196c4
package
com.taosdata.jdbc.cases
;
import
com.taosdata.jdbc.
lib.TSDBCommon
;
import
com.taosdata.jdbc.
TSDBDriver
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.*
;
import
java.util.Properties
;
import
java.util.Random
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
...
...
@@ -18,57 +16,71 @@ import static org.junit.Assert.assertEquals;
public
class
BatchInsertTest
{
static
String
host
=
"
localhost
"
;
static
String
host
=
"
127.0.0.1
"
;
static
String
dbName
=
"test"
;
static
String
stbName
=
"meters"
;
static
int
numOfTables
=
30
;
final
static
int
numOfRecordsPerTable
=
1000
;
static
long
ts
=
1496732686000
l
;
final
static
String
tablePrefix
=
"t"
;
private
Connection
connection
;
@Before
public
void
before
()
{
try
{
connection
=
TSDBCommon
.
getConn
(
host
);
TSDBCommon
.
createDatabase
(
connection
,
dbName
);
TSDBCommon
.
createStable
(
connection
,
stbName
);
TSDBCommon
.
createTables
(
connection
,
numOfTables
,
stbName
,
tablePrefix
);
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
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
);
Statement
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"use "
+
dbName
);
// create stable
String
createTableSql
=
"create table "
+
stbName
+
"(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))"
;
statement
.
executeUpdate
(
createTableSql
);
// create tables
for
(
int
i
=
0
;
i
<
numOfTables
;
i
++)
{
String
loc
=
i
%
2
==
0
?
"beijing"
:
"shanghai"
;
String
createSubTalbesSql
=
"create table "
+
tablePrefix
+
i
+
" using "
+
stbName
+
" tags("
+
i
+
", '"
+
loc
+
"')"
;
statement
.
executeUpdate
(
createSubTalbesSql
);
}
statement
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testBatchInsert
(){
public
void
testBatchInsert
()
{
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
numOfTables
);
for
(
int
i
=
0
;
i
<
numOfTables
;
i
++)
{
final
int
index
=
i
;
executorService
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
long
startTime
=
System
.
currentTimeMillis
();
Statement
statement
=
connection
.
createStatement
();
// get statement
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"INSERT INTO "
+
tablePrefix
+
index
+
" VALUES"
);
Random
rand
=
new
Random
();
for
(
int
j
=
1
;
j
<=
numOfRecordsPerTable
;
j
++)
{
sb
.
append
(
"("
+
(
ts
+
j
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
")"
);
}
statement
.
addBatch
(
sb
.
toString
());
statement
.
executeBatch
();
long
endTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"Thread "
+
index
+
" takes "
+
(
endTime
-
startTime
)
+
" microseconds"
);
connection
.
commit
();
statement
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
executorService
.
execute
(()
->
{
try
{
long
startTime
=
System
.
currentTimeMillis
();
Statement
statement
=
connection
.
createStatement
();
// get statement
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"INSERT INTO "
+
tablePrefix
+
index
+
" VALUES"
);
Random
rand
=
new
Random
();
for
(
int
j
=
1
;
j
<=
numOfRecordsPerTable
;
j
++)
{
sb
.
append
(
"("
+
(
ts
+
j
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
", "
);
sb
.
append
(
rand
.
nextInt
(
100
)
+
")"
);
}
statement
.
addBatch
(
sb
.
toString
());
statement
.
executeBatch
();
long
endTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"Thread "
+
index
+
" takes "
+
(
endTime
-
startTime
)
+
" microseconds"
);
connection
.
commit
();
statement
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
});
}
...
...
@@ -80,7 +92,7 @@ public class BatchInsertTest {
e
.
printStackTrace
();
}
try
{
try
{
Statement
statement
=
connection
.
createStatement
();
ResultSet
rs
=
statement
.
executeQuery
(
"select * from meters"
);
int
num
=
0
;
...
...
@@ -89,7 +101,7 @@ public class BatchInsertTest {
}
assertEquals
(
num
,
numOfTables
*
numOfRecordsPerTable
);
rs
.
close
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
...
...
@@ -102,7 +114,6 @@ public class BatchInsertTest {
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java
已删除
100644 → 0
浏览文件 @
142ca8ee
package
com.taosdata.jdbc.lib
;
import
com.taosdata.jdbc.TSDBDriver
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
public
class
TSDBCommon
{
public
static
Connection
getConn
(
String
host
)
throws
SQLException
,
ClassNotFoundException
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
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"
);
return
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
,
properties
);
}
public
static
void
createDatabase
(
Connection
connection
,
String
dbName
)
throws
SQLException
{
Statement
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"use "
+
dbName
);
statement
.
close
();
}
public
static
void
createStable
(
Connection
connection
,
String
stbName
)
throws
SQLException
{
Statement
statement
=
connection
.
createStatement
();
String
createTableSql
=
"create table "
+
stbName
+
"(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))"
;
statement
.
executeUpdate
(
createTableSql
);
statement
.
close
();
}
public
static
void
createTables
(
Connection
connection
,
int
numOfTables
,
String
stbName
,
String
tablePrefix
)
throws
SQLException
{
Statement
statement
=
connection
.
createStatement
();
for
(
int
i
=
0
;
i
<
numOfTables
;
i
++)
{
String
loc
=
i
%
2
==
0
?
"beijing"
:
"shanghai"
;
String
createSubTalbesSql
=
"create table "
+
tablePrefix
+
i
+
" using "
+
stbName
+
" tags("
+
i
+
", '"
+
loc
+
"')"
;
statement
.
executeUpdate
(
createSubTalbesSql
);
}
statement
.
close
();
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java
浏览文件 @
9e3196c4
...
...
@@ -16,10 +16,6 @@ public class SqlSyntaxValidatorTest {
@Test
public
void
isUseSQL
()
{
Assert
.
assertTrue
(
SqlSyntaxValidator
.
isUseSql
(
"use database test"
));
Assert
.
assertTrue
(
SqlSyntaxValidator
.
isUseSql
(
"create database test"
));
Assert
.
assertTrue
(
SqlSyntaxValidator
.
isUseSql
(
"create database if not exist test"
));
Assert
.
assertTrue
(
SqlSyntaxValidator
.
isUseSql
(
"drop database test"
));
Assert
.
assertTrue
(
SqlSyntaxValidator
.
isUseSql
(
"drop database if exist test"
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录