Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
efa75445
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
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看板
提交
efa75445
编写于
1月 26, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
42c802bd
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
152 addition
and
244 deletion
+152
-244
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/ResultSetTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
+28
-28
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
+17
-16
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
+30
-23
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
...test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
+31
-30
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/cases/BatchInsertTest.java
...rc/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java
+30
-15
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/BaseTest.java
已删除
100644 → 0
浏览文件 @
42c802bd
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/ResultSetTest.java
浏览文件 @
efa75445
...
...
@@ -13,42 +13,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
)
{
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
.
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
;
}
statement
.
executeQuery
(
"use "
+
dbName
);
}
@Test
public
void
testResultSet
()
{
String
sql
=
null
;
String
sql
;
long
ts
=
1496732686000
l
;
int
v1
=
2147483600
;
long
v2
=
ts
+
1000
;
...
...
@@ -815,13 +810,18 @@ public class ResultSetTest extends BaseTest {
assertEquals
(
res
.
length
,
2
);
statement
.
clearBatch
();
}
@AfterClass
public
static
void
close
()
throws
Exception
{
public
static
void
close
()
{
try
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
if
(
statement
!=
null
)
statement
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
Thread
.
sleep
(
10
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
浏览文件 @
efa75445
...
...
@@ -16,23 +16,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"
);
}
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
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
}
@Test
...
...
@@ -49,7 +48,6 @@ public class StatementTest {
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
...
...
@@ -173,12 +171,15 @@ public class StatementTest {
}
@AfterClass
public
static
void
close
()
throws
Exception
{
if
(!
statement
.
isClosed
())
{
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
public
static
void
close
()
{
try
{
statement
.
execute
(
"drop database if exists "
+
dbName
);
if
(
statement
!=
null
)
statement
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
Thread
.
sleep
(
10
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
浏览文件 @
efa75445
...
...
@@ -19,12 +19,9 @@ public class SubscribeTest {
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"
);
...
...
@@ -41,6 +38,10 @@ public class SubscribeTest {
String
sql
=
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", "
+
(
100
+
i
)
+
", "
+
i
+
")"
;
statement
.
executeUpdate
(
sql
);
}
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
return
;
}
}
@Test
...
...
@@ -79,10 +80,16 @@ public class SubscribeTest {
}
@After
public
void
close
()
throws
Exception
{
public
void
close
()
{
try
{
statement
.
executeQuery
(
"drop database "
+
dbName
);
if
(
statement
!=
null
)
statement
.
close
();
if
(
connection
!=
null
)
connection
.
close
();
Thread
.
sleep
(
10
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
浏览文件 @
efa75445
...
...
@@ -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
{
...
...
@@ -975,4 +947,33 @@ public class TSDBDatabaseMetaDataTest {
public
void
generatedKeyAlwaysReturned
()
throws
SQLException
{
Assert
.
assertFalse
(
metaData
.
generatedKeyAlwaysReturned
());
}
@BeforeClass
public
static
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
static
void
after
()
{
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
浏览文件 @
efa75445
...
...
@@ -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
);
}
}
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
);
}
}
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
);
}
}
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/cases/BatchInsertTest.java
浏览文件 @
efa75445
package
com.taosdata.jdbc.cases
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.lib.TSDBCommon
;
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,30 +17,47 @@ 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
;
...
...
@@ -80,7 +96,7 @@ public class BatchInsertTest {
e
.
printStackTrace
();
}
try
{
try
{
Statement
statement
=
connection
.
createStatement
();
ResultSet
rs
=
statement
.
executeQuery
(
"select * from meters"
);
int
num
=
0
;
...
...
@@ -89,7 +105,7 @@ public class BatchInsertTest {
}
assertEquals
(
num
,
numOfTables
*
numOfRecordsPerTable
);
rs
.
close
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
...
...
@@ -102,7 +118,6 @@ public class BatchInsertTest {
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java
已删除
100644 → 0
浏览文件 @
42c802bd
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
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录