Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d6303ecf
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
d6303ecf
编写于
12月 28, 2021
作者:
Z
Zhiyu Yang
提交者:
GitHub
12月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TS-1000]<test>(connector): parameter-binding demo for 2.2 version (#9438)
上级
4801f785
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
220 addition
and
1 deletion
+220
-1
tests/examples/JDBC/JDBCDemo/pom.xml
tests/examples/JDBC/JDBCDemo/pom.xml
+1
-1
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/ParameterBinding.java
.../src/main/java/com/taosdata/example/ParameterBinding.java
+219
-0
未找到文件。
tests/examples/JDBC/JDBCDemo/pom.xml
浏览文件 @
d6303ecf
...
...
@@ -17,7 +17,7 @@
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.3
6
</version>
<version>
2.0.3
4
</version>
</dependency>
</dependencies>
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/ParameterBinding.java
0 → 100644
浏览文件 @
d6303ecf
package
com.taosdata.example
;
import
com.taosdata.jdbc.TSDBPreparedStatement
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.Random
;
public
class
ParameterBinding
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
final
Random
random
=
new
Random
(
System
.
currentTimeMillis
());
private
static
final
int
BINARY_COLUMN_SIZE
=
20
;
private
static
final
String
[]
schemaList
=
{
"create table stable1(ts timestamp, f1 tinyint, f2 smallint, f3 int, f4 bigint) tags(t1 tinyint, t2 smallint, t3 int, t4 bigint)"
,
"create table stable2(ts timestamp, f1 float, f2 double) tags(t1 float, t2 double)"
,
"create table stable3(ts timestamp, f1 bool) tags(t1 bool)"
,
"create table stable4(ts timestamp, f1 binary("
+
BINARY_COLUMN_SIZE
+
")) tags(t1 binary("
+
BINARY_COLUMN_SIZE
+
"))"
,
"create table stable5(ts timestamp, f1 nchar("
+
BINARY_COLUMN_SIZE
+
")) tags(t1 nchar("
+
BINARY_COLUMN_SIZE
+
"))"
};
private
static
final
int
numOfTable
=
10
,
numOfRow
=
32767
;
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
String
jdbcUrl
=
"jdbc:TAOS://"
+
host
+
":6030/"
;
Connection
conn
=
DriverManager
.
getConnection
(
jdbcUrl
,
"root"
,
"taosdata"
);
init
(
conn
);
for
(
int
i
=
0
;
i
<
numOfTable
;
i
++)
bindInteger
(
conn
,
"t1_"
+
(
i
+
1
));
for
(
int
i
=
0
;
i
<
numOfTable
;
i
++)
bindFloat
(
conn
,
"tb2_"
+
(
i
+
1
));
for
(
int
i
=
0
;
i
<
numOfTable
;
i
++)
bindBoolean
(
conn
,
"tb3_"
+
(
i
+
1
));
for
(
int
i
=
0
;
i
<
numOfTable
;
i
++)
bindBytes
(
conn
,
"tb4_"
+
(
i
+
1
));
for
(
int
i
=
0
;
i
<
numOfTable
;
i
++)
bindString
(
conn
,
"tb5_"
+
(
i
+
1
));
conn
.
close
();
}
private
static
void
init
(
Connection
conn
)
throws
SQLException
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"drop database if exists test_parabind"
);
stmt
.
execute
(
"create database if not exists test_parabind"
);
stmt
.
execute
(
"use test_parabind"
);
for
(
int
i
=
0
;
i
<
schemaList
.
length
;
i
++)
{
stmt
.
execute
(
schemaList
[
i
]);
}
}
}
private
static
void
bindInteger
(
Connection
conn
,
String
tbname
)
throws
SQLException
{
String
sql
=
"insert into ? using stable1 tags(?,?,?,?) values(?,?,?,?,?)"
;
TSDBPreparedStatement
pstmt
=
conn
.
prepareStatement
(
sql
).
unwrap
(
TSDBPreparedStatement
.
class
);
// set table name
pstmt
.
setTableName
(
tbname
);
// set tags
pstmt
.
setTagByte
(
0
,
Byte
.
parseByte
(
Integer
.
toString
(
random
.
nextInt
(
Byte
.
MAX_VALUE
))));
pstmt
.
setTagShort
(
1
,
Short
.
parseShort
(
Integer
.
toString
(
random
.
nextInt
(
Short
.
MAX_VALUE
))));
pstmt
.
setTagInt
(
2
,
random
.
nextInt
(
Integer
.
MAX_VALUE
));
pstmt
.
setTagLong
(
3
,
random
.
nextLong
());
// set columns
ArrayList
<
Long
>
tsList
=
new
ArrayList
<>();
long
current
=
System
.
currentTimeMillis
();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
tsList
.
add
(
current
+
j
);
pstmt
.
setTimestamp
(
0
,
tsList
);
ArrayList
<
Byte
>
f1List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
f1List
.
add
(
Byte
.
parseByte
(
Integer
.
toString
(
random
.
nextInt
(
Byte
.
MAX_VALUE
))));
pstmt
.
setByte
(
1
,
f1List
);
ArrayList
<
Short
>
f2List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
f2List
.
add
(
Short
.
parseShort
(
Integer
.
toString
(
random
.
nextInt
(
Short
.
MAX_VALUE
))));
pstmt
.
setShort
(
2
,
f2List
);
ArrayList
<
Integer
>
f3List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
f3List
.
add
(
random
.
nextInt
(
Integer
.
MAX_VALUE
));
pstmt
.
setInt
(
3
,
f3List
);
ArrayList
<
Long
>
f4List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
f4List
.
add
(
random
.
nextLong
());
pstmt
.
setLong
(
4
,
f4List
);
pstmt
.
columnDataAddBatch
();
pstmt
.
columnDataExecuteBatch
();
pstmt
.
columnDataClearBatch
();
pstmt
.
columnDataCloseBatch
();
}
private
static
void
bindFloat
(
Connection
conn
,
String
tbname
)
throws
SQLException
{
String
sql
=
"insert into ? using stable2 tags(?,?) values(?,?,?)"
;
TSDBPreparedStatement
pstmt
=
conn
.
prepareStatement
(
sql
).
unwrap
(
TSDBPreparedStatement
.
class
);
// set table name
pstmt
.
setTableName
(
tbname
);
// set tags
pstmt
.
setTagFloat
(
0
,
random
.
nextFloat
());
pstmt
.
setTagDouble
(
1
,
random
.
nextDouble
());
// set columns
ArrayList
<
Long
>
tsList
=
new
ArrayList
<>();
long
current
=
System
.
currentTimeMillis
();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
tsList
.
add
(
current
+
j
);
pstmt
.
setTimestamp
(
0
,
tsList
);
ArrayList
<
Float
>
f1List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
f1List
.
add
(
random
.
nextFloat
());
pstmt
.
setFloat
(
1
,
f1List
);
ArrayList
<
Double
>
f2List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
f2List
.
add
(
random
.
nextDouble
());
pstmt
.
setDouble
(
2
,
f2List
);
pstmt
.
columnDataAddBatch
();
pstmt
.
columnDataExecuteBatch
();
pstmt
.
columnDataClearBatch
();
pstmt
.
columnDataCloseBatch
();
}
private
static
void
bindBoolean
(
Connection
conn
,
String
tbname
)
throws
SQLException
{
String
sql
=
"insert into ? using stable3 tags(?) values(?,?)"
;
TSDBPreparedStatement
pstmt
=
conn
.
prepareStatement
(
sql
).
unwrap
(
TSDBPreparedStatement
.
class
);
// set table name
pstmt
.
setTableName
(
tbname
);
// set tags
pstmt
.
setTagBoolean
(
0
,
random
.
nextBoolean
());
// set columns
ArrayList
<
Long
>
tsList
=
new
ArrayList
<>();
long
current
=
System
.
currentTimeMillis
();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
tsList
.
add
(
current
+
j
);
pstmt
.
setTimestamp
(
0
,
tsList
);
ArrayList
<
Boolean
>
f1List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
f1List
.
add
(
random
.
nextBoolean
());
pstmt
.
setBoolean
(
1
,
f1List
);
pstmt
.
columnDataAddBatch
();
pstmt
.
columnDataExecuteBatch
();
pstmt
.
columnDataClearBatch
();
pstmt
.
columnDataCloseBatch
();
}
private
static
void
bindBytes
(
Connection
conn
,
String
tbname
)
throws
SQLException
{
String
sql
=
"insert into ? using stable4 tags(?) values(?,?)"
;
TSDBPreparedStatement
pstmt
=
conn
.
prepareStatement
(
sql
).
unwrap
(
TSDBPreparedStatement
.
class
);
// set table name
pstmt
.
setTableName
(
tbname
);
// set tags
pstmt
.
setTagString
(
0
,
new
String
(
"abc"
));
// set columns
ArrayList
<
Long
>
tsList
=
new
ArrayList
<>();
long
current
=
System
.
currentTimeMillis
();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
tsList
.
add
(
current
+
j
);
pstmt
.
setTimestamp
(
0
,
tsList
);
ArrayList
<
String
>
f1List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
{
f1List
.
add
(
new
String
(
"abc"
));
}
pstmt
.
setString
(
1
,
f1List
,
BINARY_COLUMN_SIZE
);
pstmt
.
columnDataAddBatch
();
pstmt
.
columnDataExecuteBatch
();
pstmt
.
columnDataClearBatch
();
pstmt
.
columnDataCloseBatch
();
}
private
static
void
bindString
(
Connection
conn
,
String
tbname
)
throws
SQLException
{
String
sql
=
"insert into ? using stable5 tags(?) values(?,?)"
;
TSDBPreparedStatement
pstmt
=
conn
.
prepareStatement
(
sql
).
unwrap
(
TSDBPreparedStatement
.
class
);
// set table name
pstmt
.
setTableName
(
tbname
);
// set tags
pstmt
.
setTagNString
(
0
,
"北京-abc"
);
// set columns
ArrayList
<
Long
>
tsList
=
new
ArrayList
<>();
long
current
=
System
.
currentTimeMillis
();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
tsList
.
add
(
current
+
j
);
pstmt
.
setTimestamp
(
0
,
tsList
);
ArrayList
<
String
>
f1List
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfRow
;
j
++)
{
f1List
.
add
(
"北京-abc"
);
}
pstmt
.
setNString
(
1
,
f1List
,
BINARY_COLUMN_SIZE
);
pstmt
.
columnDataAddBatch
();
pstmt
.
columnDataExecuteBatch
();
pstmt
.
columnDataClearBatch
();
pstmt
.
columnDataCloseBatch
();
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录