Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
d96f57a8
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看板
提交
d96f57a8
编写于
1月 21, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
c8b6ff86
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
61 deletion
+48
-61
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
...ctor/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
+48
-61
未找到文件。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
浏览文件 @
d96f57a8
...
...
@@ -12,69 +12,66 @@ import java.util.Properties;
import
static
org
.
junit
.
Assert
.
assertEquals
;
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
public
class
StableTest
extends
BaseTest
{
static
Connection
connection
=
null
;
static
Statement
statement
=
null
;
public
class
StableTest
{
static
Connection
connection
;
static
String
dbName
=
"test"
;
static
String
stbName
=
"st"
;
static
String
host
=
"
localhost
"
;
static
String
host
=
"
127.0.0.1
"
;
@BeforeClass
public
static
void
createDatabase
()
throws
SQLException
{
public
static
void
createDatabase
()
{
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/"
,
properties
);
Statement
statement
=
connection
.
createStatement
();
statement
.
execute
(
"create database if not exists "
+
dbName
);
statement
.
execute
(
"use "
+
dbName
);
statement
.
close
();
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
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
.
executeQuery
(
"use "
+
dbName
);
}
// @Test
public
void
createStable
()
{
String
sql
=
"create table "
+
stbName
+
" (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) "
;
try
{
statement
.
executeUpdate
(
sql
);
@Test
public
void
case001_createSuperTable
()
{
try
(
Statement
stmt
=
connection
.
createStatement
())
{
final
String
sql
=
"create table "
+
stbName
+
" (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) "
;
stmt
.
execute
(
sql
);
}
catch
(
SQLException
e
)
{
assert
false
:
"error create stable"
+
e
.
getMessage
();
}
}
// @Test
public
void
createTable
()
{
String
sql
=
"create table t1 using "
+
stbName
+
" tags (\"beijing\")"
;
try
{
statement
.
executeUpdate
(
sql
);
@Test
public
void
case002_createTable
()
{
try
(
Statement
stmt
=
connection
.
createStatement
())
{
final
String
sql
=
"create table t1 using "
+
stbName
+
" tags (\"beijing\")"
;
stmt
.
execute
(
sql
);
}
catch
(
SQLException
e
)
{
assert
false
:
"error create table"
+
e
.
getMessage
();
}
}
@Test
public
void
describeSTable
()
{
createStable
();
String
sql
=
"describe "
+
stbName
;
public
void
case003_describeSTable
()
{
int
num
=
0
;
System
.
out
.
println
(
"describe stable"
);
try
{
ResultSet
r
es
=
statemen
t
.
executeQuery
(
sql
);
while
(
r
e
s
.
next
())
{
for
(
int
i
=
1
;
i
<=
r
e
s
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
print
f
(
"%d: %s\n"
,
i
,
re
s
.
getString
(
i
));
try
(
Statement
stmt
=
connection
.
createStatement
())
{
String
sql
=
"describe "
+
stbName
;
ResultSet
r
s
=
stm
t
.
executeQuery
(
sql
);
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
rs
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
print
ln
(
i
+
":"
+
r
s
.
getString
(
i
));
}
num
++;
}
r
e
s
.
close
();
rs
.
close
();
assertEquals
(
4
,
num
);
}
catch
(
SQLException
e
)
{
assert
false
:
"error describe stable"
+
e
.
getMessage
();
...
...
@@ -82,41 +79,31 @@ public class StableTest extends BaseTest {
}
@Test
public
void
describeTable
()
{
createTable
();
String
sql
=
"describe t1"
;
public
void
case004_describeTable
()
{
int
num
=
0
;
System
.
out
.
println
(
"describe table"
);
try
{
ResultSet
res
=
statement
.
executeQuery
(
sql
);
while
(
res
.
next
())
{
for
(
int
i
=
1
;
i
<=
res
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
printf
(
"%d: %s\n"
,
i
,
res
.
getString
(
i
));
try
(
Statement
stmt
=
connection
.
createStatement
())
{
ResultSet
rs
=
stmt
.
executeQuery
(
"describe t1"
);
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
rs
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
printf
(
"%d: %s\n"
,
i
,
rs
.
getString
(
i
));
}
num
++;
}
r
e
s
.
close
();
rs
.
close
();
assertEquals
(
4
,
num
);
}
catch
(
SQLException
e
)
{
assert
false
:
"error describe stable"
+
e
.
getMessage
();
}
}
// @Test
public
void
validCreateSql
()
{
String
sql
=
"create table t2 using "
+
stbName
+
" tags (\"beijing\")"
;
boolean
valid
=
((
TSDBConnection
)
connection
).
getConnection
().
validateCreateTableSql
(
sql
);
assertEquals
(
true
,
valid
);
}
@AfterClass
public
static
void
close
()
throws
Exception
{
if
(!
statement
.
isClosed
())
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
Thread
.
sleep
(
10
);
public
static
void
close
()
{
try
{
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录