提交 0778cb95 编写于 作者: Z zyyang

remove e.printStackTrace

上级 e4b38111
...@@ -413,8 +413,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -413,8 +413,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
status = future.get(); status = future.get();
else else
status = future.get(timeout, TimeUnit.SECONDS); status = future.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException ignored) {
e.printStackTrace();
} catch (TimeoutException e) { } catch (TimeoutException e) {
future.cancel(true); future.cancel(true);
status = false; status = false;
......
...@@ -597,7 +597,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -597,7 +597,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return col4; return col4;
} }
public ResultSet getSchemas() throws SQLException { public ResultSet getSchemas() {
return getEmptyResultSet(); return getEmptyResultSet();
} }
...@@ -629,7 +629,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -629,7 +629,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException; public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) { protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) throws SQLException {
if (catalog == null || catalog.isEmpty()) if (catalog == null || catalog.isEmpty())
return null; return null;
if (!isAvailableCatalog(conn, catalog)) if (!isAvailableCatalog(conn, catalog))
...@@ -682,8 +682,6 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -682,8 +682,6 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
rowIndex++; rowIndex++;
} }
resultSet.setRowDataList(rowDataList); resultSet.setRowDataList(rowDataList);
} catch (SQLException e) {
e.printStackTrace();
} }
return resultSet; return resultSet;
} }
...@@ -1220,7 +1218,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -1220,7 +1218,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return col6; return col6;
} }
private boolean isAvailableCatalog(Connection connection, String catalog) { private boolean isAvailableCatalog(Connection connection, String catalog) throws SQLException {
try (Statement stmt = connection.createStatement(); try (Statement stmt = connection.createStatement();
ResultSet databases = stmt.executeQuery("show databases")) { ResultSet databases = stmt.executeQuery("show databases")) {
while (databases.next()) { while (databases.next()) {
...@@ -1229,8 +1227,6 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da ...@@ -1229,8 +1227,6 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
if (dbname.equalsIgnoreCase(catalog)) if (dbname.equalsIgnoreCase(catalog))
return true; return true;
} }
} catch (SQLException e) {
e.printStackTrace();
} }
return false; return false;
} }
......
...@@ -21,6 +21,7 @@ import com.taosdata.jdbc.enums.SchemalessProtocolType; ...@@ -21,6 +21,7 @@ import com.taosdata.jdbc.enums.SchemalessProtocolType;
import com.taosdata.jdbc.enums.SchemalessTimestampType; import com.taosdata.jdbc.enums.SchemalessTimestampType;
import com.taosdata.jdbc.utils.TaosInfo; import com.taosdata.jdbc.utils.TaosInfo;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
...@@ -107,8 +108,7 @@ public class TSDBJNIConnector { ...@@ -107,8 +108,7 @@ public class TSDBJNIConnector {
try { try {
pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos); pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos);
taosInfo.stmt_count_increment(); taosInfo.stmt_count_increment();
} catch (Exception e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace();
this.freeResultSetImp(this.taos, pSql); this.freeResultSetImp(this.taos, pSql);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING);
} }
......
...@@ -611,7 +611,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat ...@@ -611,7 +611,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
try { try {
this.tagValueLength += value.getBytes(charset).length; this.tagValueLength += value.getBytes(charset).length;
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); throw new RuntimeException(e.getMessage());
} }
} }
...@@ -786,7 +786,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat ...@@ -786,7 +786,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
b = val.getBytes(charset); b = val.getBytes(charset);
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); throw new RuntimeException(e.getMessage());
} }
tagDataList.put(b); tagDataList.put(b);
...@@ -921,7 +921,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat ...@@ -921,7 +921,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
b = val.getBytes(charset); b = val.getBytes(charset);
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); throw new RuntimeException(e.getMessage());
} }
if (val.length() > col1.bytes) { if (val.length() > col1.bytes) {
......
...@@ -92,7 +92,6 @@ public class TSDBResultSetBlockData { ...@@ -92,7 +92,6 @@ public class TSDBResultSetBlockData {
} }
public void setByteArray(int col, int length, byte[] value) { public void setByteArray(int col, int length, byte[] value) {
try {
switch (this.columnMetaDataList.get(col).getColType()) { switch (this.columnMetaDataList.get(col).getColType()) {
case TSDBConstants.TSDB_DATA_TYPE_BOOL: { case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
ByteBuffer buf = ByteBuffer.wrap(value, 0, length); ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
...@@ -159,9 +158,6 @@ public class TSDBResultSetBlockData { ...@@ -159,9 +158,6 @@ public class TSDBResultSetBlockData {
break; break;
} }
} }
} catch (Exception e) {
e.printStackTrace();
}
} }
...@@ -283,14 +279,8 @@ public class TSDBResultSetBlockData { ...@@ -283,14 +279,8 @@ public class TSDBResultSetBlockData {
return 0; return 0;
} }
public Timestamp getTimestamp(int col) { public Timestamp getTimestamp(int col) throws SQLException {
try {
return new Timestamp(getLong(col)); return new Timestamp(getLong(col));
} catch (SQLException e) {
e.printStackTrace();
}
return null;
} }
public double getDouble(int col) { public double getDouble(int col) {
...@@ -429,7 +419,7 @@ public class TSDBResultSetBlockData { ...@@ -429,7 +419,7 @@ public class TSDBResultSetBlockData {
String charset = TaosGlobalConfig.getCharset(); String charset = TaosGlobalConfig.getCharset();
return new String(dest, charset); return new String(dest, charset);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); throw new RuntimeException(e.getMessage());
} }
} }
} }
......
...@@ -16,6 +16,7 @@ package com.taosdata.jdbc; ...@@ -16,6 +16,7 @@ package com.taosdata.jdbc;
import com.taosdata.jdbc.utils.NullType; import com.taosdata.jdbc.utils.NullType;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -378,8 +379,8 @@ public class TSDBResultSetRowData { ...@@ -378,8 +379,8 @@ public class TSDBResultSetRowData {
// this setByteArr(int, byte[]) to handle NCHAR value, we need to build a String with charsetEncoding by TaosGlobalConfig // this setByteArr(int, byte[]) to handle NCHAR value, we need to build a String with charsetEncoding by TaosGlobalConfig
try { try {
data.set(col, new String(value, TaosGlobalConfig.getCharset())); data.set(col, new String(value, TaosGlobalConfig.getCharset()));
} catch (Exception e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); throw new RuntimeException(e.getMessage());
} }
} }
......
...@@ -16,8 +16,8 @@ public class TaosInfo implements TaosInfoMBean { ...@@ -16,8 +16,8 @@ public class TaosInfo implements TaosInfoMBean {
MBeanServer server = ManagementFactory.getPlatformMBeanServer(); MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("TaosInfoMBean:name=TaosInfo"); ObjectName name = new ObjectName("TaosInfoMBean:name=TaosInfo");
server.registerMBean(TaosInfo.getInstance(), name); server.registerMBean(TaosInfo.getInstance(), name);
} catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) { } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException ignored) {
e.printStackTrace(); throw new RuntimeException("registerMBean failed");
} }
} }
......
...@@ -33,7 +33,6 @@ public class TSDBDriverTest { ...@@ -33,7 +33,6 @@ public class TSDBDriverTest {
conn = DriverManager.getConnection(url); conn = DriverManager.getConnection(url);
assertNotNull("failure - connection should not be null", conn); assertNotNull("failure - connection should not be null", conn);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace();
fail("failure - should not throw Exception"); fail("failure - should not throw Exception");
} }
} }
...@@ -49,7 +48,6 @@ public class TSDBDriverTest { ...@@ -49,7 +48,6 @@ public class TSDBDriverTest {
conn = DriverManager.getConnection(jdbcUrl, connProps); conn = DriverManager.getConnection(jdbcUrl, connProps);
assertNotNull("failure - connection should not be null", conn); assertNotNull("failure - connection should not be null", conn);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace();
fail("failure - should not throw Exception"); fail("failure - should not throw Exception");
} }
} }
...@@ -65,7 +63,6 @@ public class TSDBDriverTest { ...@@ -65,7 +63,6 @@ public class TSDBDriverTest {
conn = DriverManager.getConnection(jdbcUrl, connProps); conn = DriverManager.getConnection(jdbcUrl, connProps);
assertNotNull("failure - connection should not be null", conn); assertNotNull("failure - connection should not be null", conn);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace();
fail("failure - should not throw Exception"); fail("failure - should not throw Exception");
} }
} }
...@@ -157,16 +154,8 @@ public class TSDBDriverTest { ...@@ -157,16 +154,8 @@ public class TSDBDriverTest {
} }
@Test @Test
public void getParentLogger() throws SQLFeatureNotSupportedException { public void getParentLogger() {
assertNull(new TSDBDriver().getParentLogger()); assertNull(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
...@@ -57,44 +57,31 @@ public class AuthenticationTest { ...@@ -57,44 +57,31 @@ public class AuthenticationTest {
@Ignore @Ignore
@Test @Test
public void test() { public void test() throws SQLException {
// change password // change password
try { String url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata";
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata"); try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();) {
stmt.execute("alter user " + user + " pass '" + password + "'"); stmt.execute("alter user " + user + " pass '" + password + "'");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} }
// use new to login and execute query // use new to login and execute query
try { url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password;
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password); try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement()) {
stmt.execute("show databases"); stmt.execute("show databases");
ResultSet rs = stmt.getResultSet(); ResultSet rs = stmt.getResultSet();
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) { while (rs.next()) {
for (int i = 1; i <= meta.getColumnCount(); i++) {
System.out.print(meta.getColumnLabel(i) + ":" + rs.getString(i) + "\t");
} }
System.out.println();
}
} catch (SQLException e) {
e.printStackTrace();
} }
// change password back // change password back
try { url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password;
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password); try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement()) {
stmt.execute("alter user " + user + " pass 'taosdata'"); stmt.execute("alter user " + user + " pass 'taosdata'");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Before @Before
......
...@@ -19,16 +19,14 @@ public class BatchErrorIgnoreTest { ...@@ -19,16 +19,14 @@ public class BatchErrorIgnoreTest {
IntStream.range(1, 6).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + ")").forEach(sql -> { IntStream.range(1, 6).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + ")").forEach(sql -> {
try { try {
stmt.addBatch(sql); stmt.addBatch(sql);
} catch (SQLException e) { } catch (SQLException ignored) {
e.printStackTrace();
} }
}); });
stmt.addBatch("insert into t11 values(now, 11)"); stmt.addBatch("insert into t11 values(now, 11)");
IntStream.range(6, 11).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + "),(now + 1s, " + (10 * i) + ")").forEach(sql -> { IntStream.range(6, 11).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + "),(now + 1s, " + (10 * i) + ")").forEach(sql -> {
try { try {
stmt.addBatch(sql); stmt.addBatch(sql);
} catch (SQLException e) { } catch (SQLException ignored) {
e.printStackTrace();
} }
}); });
stmt.addBatch("select count(*) from test.weather"); stmt.addBatch("select count(*) from test.weather");
...@@ -57,23 +55,19 @@ public class BatchErrorIgnoreTest { ...@@ -57,23 +55,19 @@ public class BatchErrorIgnoreTest {
IntStream.range(1, 6).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + ")").forEach(sql -> { IntStream.range(1, 6).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + ")").forEach(sql -> {
try { try {
stmt.addBatch(sql); stmt.addBatch(sql);
} catch (SQLException e) { } catch (SQLException ignored) {
e.printStackTrace();
} }
}); });
stmt.addBatch("insert into t11 values(now, 11)"); stmt.addBatch("insert into t11 values(now, 11)");
IntStream.range(6, 11).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + "),(now + 1s, " + (10 * i) + ")").forEach(sql -> { IntStream.range(6, 11).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + "),(now + 1s, " + (10 * i) + ")").forEach(sql -> {
try { try {
stmt.addBatch(sql); stmt.addBatch(sql);
} catch (SQLException e) { } catch (SQLException ignored) {
e.printStackTrace();
} }
}); });
stmt.addBatch("select count(*) from test.weather"); stmt.addBatch("select count(*) from test.weather");
results = stmt.executeBatch(); results = stmt.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -94,10 +88,10 @@ public class BatchErrorIgnoreTest { ...@@ -94,10 +88,10 @@ public class BatchErrorIgnoreTest {
} }
@Before @Before
public void before() { public void before() throws SQLException {
try { try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); Statement stmt = conn.createStatement();) {
Statement stmt = conn.createStatement();
stmt.execute("use test"); stmt.execute("use test");
stmt.execute("drop table if exists weather"); stmt.execute("drop table if exists weather");
stmt.execute("create table weather (ts timestamp, f1 float) tags(t1 int)"); stmt.execute("create table weather (ts timestamp, f1 float) tags(t1 int)");
...@@ -108,37 +102,25 @@ public class BatchErrorIgnoreTest { ...@@ -108,37 +102,25 @@ public class BatchErrorIgnoreTest {
e.printStackTrace(); e.printStackTrace();
} }
}); });
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() throws SQLException {
try { try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); Statement stmt = conn.createStatement()) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test"); stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test"); stmt.execute("create database if not exists test");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@AfterClass @AfterClass
public static void afterClass() { public static void afterClass() throws SQLException {
try { try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); Statement stmt = conn.createStatement()) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test"); stmt.execute("drop database if exists test");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} }
} }
} }
...@@ -20,22 +20,20 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { ...@@ -20,22 +20,20 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest {
private Connection conn2; private Connection conn2;
@Test @Test
public void test() { public void test() throws SQLException {
//when //when
executeSelectStatus(conn1); executeSelectStatus(conn1);
executeSelectStatus(conn2); executeSelectStatus(conn2);
executeSelectStatus(conn1); executeSelectStatus(conn1);
} }
private void executeSelectStatus(Connection connection) { private void executeSelectStatus(Connection connection) throws SQLException {
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery("select server_status()"); ResultSet rs = stmt.executeQuery("select server_status()");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
Assert.assertNotNull(meta); Assert.assertNotNull(meta);
while (rs.next()) { while (rs.next()) {
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
......
package com.taosdata.jdbc.cases; package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBErrorNumbers;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.sql.DriverManager; import java.sql.DriverManager;
...@@ -9,16 +7,9 @@ import java.sql.SQLException; ...@@ -9,16 +7,9 @@ import java.sql.SQLException;
public class ConnectWrongDatabaseTest { public class ConnectWrongDatabaseTest {
@Test @Test(expected = SQLException.class)
public void connect() { public void connect() throws SQLException {
try {
Class.forName("com.taosdata.jdbc.TSDBDriver");
DriverManager.getConnection("jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata"); DriverManager.getConnection("jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
Assert.assertEquals(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, e.getErrorCode());
}
} }
} }
...@@ -11,7 +11,7 @@ public class DatetimeBefore1970Test { ...@@ -11,7 +11,7 @@ public class DatetimeBefore1970Test {
private Connection conn; private Connection conn;
@Test @Test
public void test() { public void test() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
// given // given
stmt.executeUpdate("insert into weather(ts) values('1969-12-31 23:59:59.999')"); stmt.executeUpdate("insert into weather(ts) values('1969-12-31 23:59:59.999')");
...@@ -45,15 +45,11 @@ public class DatetimeBefore1970Test { ...@@ -45,15 +45,11 @@ public class DatetimeBefore1970Test {
// then // then
ts = rs.getTimestamp("ts"); ts = rs.getTimestamp("ts");
Assert.assertEquals("1970-01-01 07:59:59.999", TimestampUtil.longToDatetime(ts.getTime())); Assert.assertEquals("1970-01-01 07:59:59.999", TimestampUtil.longToDatetime(ts.getTime()));
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Before @Before
public void before() { public void before() throws SQLException {
try {
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test_timestamp"); stmt.execute("drop database if exists test_timestamp");
...@@ -61,20 +57,13 @@ public class DatetimeBefore1970Test { ...@@ -61,20 +57,13 @@ public class DatetimeBefore1970Test {
stmt.execute("use test_timestamp"); stmt.execute("use test_timestamp");
stmt.execute("create table weather(ts timestamp,f1 float)"); stmt.execute("create table weather(ts timestamp,f1 float)");
stmt.close(); stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@After @After
public void after() { public void after() throws SQLException {
try {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test_timestamp"); stmt.execute("drop database if exists test_timestamp");
if (conn != null) if (conn != null)
conn.close(); conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -17,29 +17,6 @@ public class ImportTest { ...@@ -17,29 +17,6 @@ public class ImportTest {
static String host = "127.0.0.1"; static String host = "127.0.0.1";
private static long ts; private static long ts;
@BeforeClass
public static void before() {
try {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
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("create database if not exists " + dbName);
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
stmt.close();
ts = System.currentTimeMillis();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test @Test
public void case001_insertData() throws Exception { public void case001_insertData() throws Exception {
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
...@@ -52,28 +29,25 @@ public class ImportTest { ...@@ -52,28 +29,25 @@ public class ImportTest {
} }
@Test @Test
public void case002_checkSum() { public void case002_checkSum() throws SQLException {
Assert.assertEquals(50, select()); Assert.assertEquals(50, select());
} }
private int select() { private int select() throws SQLException {
int count = 0; int count = 0;
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
String sql = "select * from " + dbName + "." + tName; String sql = "select * from " + dbName + "." + tName;
ResultSet rs = stmt.executeQuery(sql); ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) { while (rs.next()) {
count++; count++;
} }
rs.close(); rs.close();
} catch (SQLException e) {
e.printStackTrace();
} }
return count; return count;
} }
@Test @Test
public void case003_importData() { public void case003_importData() throws SQLException {
// 避免时间重复 // 避免时间重复
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
StringBuilder sqlBuilder = new StringBuilder("import into ").append(dbName).append(".").append(tName).append(" values "); StringBuilder sqlBuilder = new StringBuilder("import into ").append(dbName).append(".").append(tName).append(" values ");
...@@ -84,27 +58,40 @@ public class ImportTest { ...@@ -84,27 +58,40 @@ public class ImportTest {
} }
int rows = stmt.executeUpdate(sqlBuilder.toString()); int rows = stmt.executeUpdate(sqlBuilder.toString());
assertEquals(50, rows); assertEquals(50, rows);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void case004_checkSum() { public void case004_checkSum() throws SQLException {
Assert.assertEquals(100, select()); Assert.assertEquals(100, select());
} }
@BeforeClass
public static void before() throws SQLException {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
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("create database if not exists " + dbName);
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
stmt.close();
ts = System.currentTimeMillis();
}
@AfterClass @AfterClass
public static void close() { public static void close() throws SQLException {
try {
if (connection != null) { if (connection != null) {
Statement statement = connection.createStatement(); Statement statement = connection.createStatement();
statement.executeUpdate("drop database " + dbName); statement.executeUpdate("drop database " + dbName);
statement.close(); statement.close();
connection.close(); connection.close();
} }
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -23,7 +23,7 @@ public class MicroSecondPrecisionRestfulTest { ...@@ -23,7 +23,7 @@ public class MicroSecondPrecisionRestfulTest {
private static Connection conn3; private static Connection conn3;
@Test @Test
public void testCase1() { public void testCase1() throws SQLException {
try (Statement stmt = conn1.createStatement()) { try (Statement stmt = conn1.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather");
rs.next(); rs.next();
...@@ -31,13 +31,11 @@ public class MicroSecondPrecisionRestfulTest { ...@@ -31,13 +31,11 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
ts = rs.getLong(1); ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void testCase2() { public void testCase2() throws SQLException {
try (Statement stmt = conn1.createStatement()) { try (Statement stmt = conn1.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather");
rs.next(); rs.next();
...@@ -50,13 +48,11 @@ public class MicroSecondPrecisionRestfulTest { ...@@ -50,13 +48,11 @@ public class MicroSecondPrecisionRestfulTest {
ts = rs.getLong(1); ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void testCase3() { public void testCase3() throws SQLException {
try (Statement stmt = conn2.createStatement()) { try (Statement stmt = conn2.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather");
rs.next(); rs.next();
...@@ -65,13 +61,11 @@ public class MicroSecondPrecisionRestfulTest { ...@@ -65,13 +61,11 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
ts = rs.getLong(1); ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void testCase4() { public void testCase4() throws SQLException {
try (Statement stmt = conn2.createStatement()) { try (Statement stmt = conn2.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather");
rs.next(); rs.next();
...@@ -84,13 +78,11 @@ public class MicroSecondPrecisionRestfulTest { ...@@ -84,13 +78,11 @@ public class MicroSecondPrecisionRestfulTest {
ts = rs.getLong(1); ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void testCase5() { public void testCase5() throws SQLException {
try (Statement stmt = conn3.createStatement()) { try (Statement stmt = conn3.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather");
rs.next(); rs.next();
...@@ -99,13 +91,11 @@ public class MicroSecondPrecisionRestfulTest { ...@@ -99,13 +91,11 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
ts = rs.getLong(1); ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void testCase6() { public void testCase6() throws SQLException {
try (Statement stmt = conn3.createStatement()) { try (Statement stmt = conn3.createStatement()) {
ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather");
rs.next(); rs.next();
...@@ -118,8 +108,6 @@ public class MicroSecondPrecisionRestfulTest { ...@@ -118,8 +108,6 @@ public class MicroSecondPrecisionRestfulTest {
ts = rs.getLong(1); ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts); Assert.assertEquals(timestamp1, ts);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
...@@ -154,16 +142,12 @@ public class MicroSecondPrecisionRestfulTest { ...@@ -154,16 +142,12 @@ public class MicroSecondPrecisionRestfulTest {
} }
@AfterClass @AfterClass
public static void afterClass() { public static void afterClass() throws SQLException {
try {
if (conn1 != null) if (conn1 != null)
conn1.close(); conn1.close();
if (conn2 != null) if (conn2 != null)
conn2.close(); conn2.close();
if (conn3 != null) if (conn3 != null)
conn3.close(); conn3.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit; ...@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
public class MultiConnectionWithDifferentDbTest { public class MultiConnectionWithDifferentDbTest {
...@@ -26,16 +25,17 @@ public class MultiConnectionWithDifferentDbTest { ...@@ -26,16 +25,17 @@ public class MultiConnectionWithDifferentDbTest {
@Override @Override
public void run() { public void run() {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
queryDb();
try { try {
queryDb();
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) { } catch (InterruptedException ignored) {
e.printStackTrace(); } catch (SQLException throwables) {
fail();
} }
} }
} }
private void queryDb() { private void queryDb() throws SQLException {
String url = "jdbc:TAOS-RS://" + host + ":6041/db" + i + "?user=root&password=taosdata"; String url = "jdbc:TAOS-RS://" + host + ":6041/db" + i + "?user=root&password=taosdata";
try (Connection connection = DriverManager.getConnection(url)) { try (Connection connection = DriverManager.getConnection(url)) {
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
...@@ -54,8 +54,6 @@ public class MultiConnectionWithDifferentDbTest { ...@@ -54,8 +54,6 @@ public class MultiConnectionWithDifferentDbTest {
assertEquals(loc, loc_actual); assertEquals(loc, loc_actual);
stmt.close(); stmt.close();
} catch (SQLException e) {
e.printStackTrace();
} }
} }
}, "thread-" + i)).collect(Collectors.toList()); }, "thread-" + i)).collect(Collectors.toList());
...@@ -73,12 +71,10 @@ public class MultiConnectionWithDifferentDbTest { ...@@ -73,12 +71,10 @@ public class MultiConnectionWithDifferentDbTest {
} }
@Before @Before
public void before() { public void before() throws SQLException {
ts = System.currentTimeMillis(); ts = System.currentTimeMillis();
try { try (Connection conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata")) {
Connection conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + db1); stmt.execute("drop database if exists " + db1);
stmt.execute("create database if not exists " + db1); stmt.execute("create database if not exists " + db1);
...@@ -91,10 +87,6 @@ public class MultiConnectionWithDifferentDbTest { ...@@ -91,10 +87,6 @@ public class MultiConnectionWithDifferentDbTest {
stmt.execute("use " + db2); stmt.execute("use " + db2);
stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))"); stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))");
stmt.execute("insert into t1 using weather tags('shanghai') values(" + ts + ", 2)"); stmt.execute("insert into t1 using weather tags('shanghai') values(" + ts + ", 2)");
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} }
} }
......
package com.taosdata.jdbc.cases;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.util.concurrent.TimeUnit;
public class MultiThreadsWithSameStatementTest {
private static class Service {
public Connection conn;
public Statement stmt;
public Service() {
try {
conn = DriverManager.getConnection("jdbc:TAOS://localhost:6030/?user=root&password=taosdata");
stmt = conn.createStatement();
stmt.execute("create database if not exists jdbctest");
stmt.executeUpdate("create table if not exists jdbctest.weather (ts timestamp, f1 int)");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void release() {
try {
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
@Before
public void before() {
}
@Test
public void test() {
Thread t1 = new Thread(() -> {
try {
Service service = new Service();
ResultSet resultSet = service.stmt.executeQuery("select * from jdbctest.weather");
while (resultSet.next()) {
ResultSetMetaData metaData = resultSet.getMetaData();
}
resultSet.close();
service.release();
} catch (SQLException e) {
e.printStackTrace();
}
});
Thread t2 = new Thread(() -> {
while (true) {
try {
Service service = new Service();
service.stmt.executeUpdate("insert into jdbctest.weather values(now,1)");
service.release();
} catch (SQLException e) {
e.printStackTrace();
}
}
});
t1.start();
sleep(1000);
t2.start();
}
private void sleep(long mills) {
try {
TimeUnit.MILLISECONDS.sleep(mills);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@After
public void after() {
}
}
...@@ -17,7 +17,7 @@ public class NanoSecondTimestampJNITest { ...@@ -17,7 +17,7 @@ public class NanoSecondTimestampJNITest {
private static Connection conn; private static Connection conn;
@Test @Test
public void insertUsingLongValue() { public void insertUsingLongValue() throws SQLException {
// given // given
long ms = System.currentTimeMillis(); long ms = System.currentTimeMillis();
long ns = ms * 1000_000 + random.nextInt(1000_000); long ns = ms * 1000_000 + random.nextInt(1000_000);
...@@ -26,8 +26,6 @@ public class NanoSecondTimestampJNITest { ...@@ -26,8 +26,6 @@ public class NanoSecondTimestampJNITest {
int ret = 0; int ret = 0;
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)");
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -35,15 +33,13 @@ public class NanoSecondTimestampJNITest { ...@@ -35,15 +33,13 @@ public class NanoSecondTimestampJNITest {
} }
@Test @Test
public void insertUsingStringValue() { public void insertUsingStringValue() throws SQLException {
// given // given
// when // when
int ret = 0; int ret = 0;
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)"); ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)");
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -51,7 +47,7 @@ public class NanoSecondTimestampJNITest { ...@@ -51,7 +47,7 @@ public class NanoSecondTimestampJNITest {
} }
@Test @Test
public void insertUsingTimestampValue() { public void insertUsingTimestampValue() throws SQLException {
// given // given
long epochSec = System.currentTimeMillis() / 1000; long epochSec = System.currentTimeMillis() / 1000;
long nanoAdjustment = random.nextInt(1000_000_000); long nanoAdjustment = random.nextInt(1000_000_000);
...@@ -65,8 +61,6 @@ public class NanoSecondTimestampJNITest { ...@@ -65,8 +61,6 @@ public class NanoSecondTimestampJNITest {
pstmt.setFloat(2, 12.34f); pstmt.setFloat(2, 12.34f);
pstmt.setInt(3, 55); pstmt.setInt(3, 55);
ret = pstmt.executeUpdate(); ret = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -85,8 +79,6 @@ public class NanoSecondTimestampJNITest { ...@@ -85,8 +79,6 @@ public class NanoSecondTimestampJNITest {
stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)");
rs = stmt.executeQuery("select * from weather"); rs = stmt.executeQuery("select * from weather");
rs.next(); rs.next();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -102,13 +94,11 @@ public class NanoSecondTimestampJNITest { ...@@ -102,13 +94,11 @@ public class NanoSecondTimestampJNITest {
String timestampStr = "2021-01-01 12:00:00.123456789"; String timestampStr = "2021-01-01 12:00:00.123456789";
// when // when
ResultSet rs = null; ResultSet rs;
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)"); stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)");
rs = stmt.executeQuery("select * from weather"); rs = stmt.executeQuery("select * from weather");
rs.next(); rs.next();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -133,8 +123,6 @@ public class NanoSecondTimestampJNITest { ...@@ -133,8 +123,6 @@ public class NanoSecondTimestampJNITest {
pstmt.setFloat(2, 12.34f); pstmt.setFloat(2, 12.34f);
pstmt.setInt(3, 55); pstmt.setInt(3, 55);
pstmt.executeUpdate(); pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} }
// when // when
...@@ -142,8 +130,6 @@ public class NanoSecondTimestampJNITest { ...@@ -142,8 +130,6 @@ public class NanoSecondTimestampJNITest {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery("select * from weather"); rs = stmt.executeQuery("select * from weather");
rs.next(); rs.next();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -156,26 +142,21 @@ public class NanoSecondTimestampJNITest { ...@@ -156,26 +142,21 @@ public class NanoSecondTimestampJNITest {
} }
@Before @Before
public void before() { public void before() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.execute("drop table if exists weather"); stmt.execute("drop table if exists weather");
stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); stmt.execute("create table weather(ts timestamp, temperature float, humidity int)");
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() throws SQLException {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
try {
conn = DriverManager.getConnection(url); conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(); try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname); stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname + " precision 'ns'"); stmt.execute("create database if not exists " + dbname + " precision 'ns'");
stmt.execute("use " + dbname); stmt.execute("use " + dbname);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
......
...@@ -17,7 +17,7 @@ public class NanoSecondTimestampRestfulTest { ...@@ -17,7 +17,7 @@ public class NanoSecondTimestampRestfulTest {
private static Connection conn; private static Connection conn;
@Test @Test
public void insertUsingLongValue() { public void insertUsingLongValue() throws SQLException {
// given // given
long ms = System.currentTimeMillis(); long ms = System.currentTimeMillis();
long ns = ms * 1000_000 + random.nextInt(1000_000); long ns = ms * 1000_000 + random.nextInt(1000_000);
...@@ -26,8 +26,6 @@ public class NanoSecondTimestampRestfulTest { ...@@ -26,8 +26,6 @@ public class NanoSecondTimestampRestfulTest {
int ret = 0; int ret = 0;
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)");
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -35,15 +33,13 @@ public class NanoSecondTimestampRestfulTest { ...@@ -35,15 +33,13 @@ public class NanoSecondTimestampRestfulTest {
} }
@Test @Test
public void insertUsingStringValue() { public void insertUsingStringValue() throws SQLException {
// given // given
// when // when
int ret = 0; int ret = 0;
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)"); ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)");
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -51,7 +47,7 @@ public class NanoSecondTimestampRestfulTest { ...@@ -51,7 +47,7 @@ public class NanoSecondTimestampRestfulTest {
} }
@Test @Test
public void insertUsingTimestampValue() { public void insertUsingTimestampValue() throws SQLException {
// given // given
long epochSec = System.currentTimeMillis() / 1000; long epochSec = System.currentTimeMillis() / 1000;
long nanoAdjustment = random.nextInt(1000_000_000); long nanoAdjustment = random.nextInt(1000_000_000);
...@@ -65,8 +61,6 @@ public class NanoSecondTimestampRestfulTest { ...@@ -65,8 +61,6 @@ public class NanoSecondTimestampRestfulTest {
pstmt.setFloat(2, 12.34f); pstmt.setFloat(2, 12.34f);
pstmt.setInt(3, 55); pstmt.setInt(3, 55);
ret = pstmt.executeUpdate(); ret = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -80,13 +74,11 @@ public class NanoSecondTimestampRestfulTest { ...@@ -80,13 +74,11 @@ public class NanoSecondTimestampRestfulTest {
long ns = ms * 1000_000L + random.nextInt(1000_000); long ns = ms * 1000_000L + random.nextInt(1000_000);
// when // when
ResultSet rs = null; ResultSet rs;
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)");
rs = stmt.executeQuery("select * from weather"); rs = stmt.executeQuery("select * from weather");
rs.next(); rs.next();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -102,13 +94,11 @@ public class NanoSecondTimestampRestfulTest { ...@@ -102,13 +94,11 @@ public class NanoSecondTimestampRestfulTest {
String timestampStr = "2021-01-01 12:00:00.123456789"; String timestampStr = "2021-01-01 12:00:00.123456789";
// when // when
ResultSet rs = null; ResultSet rs;
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)"); stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)");
rs = stmt.executeQuery("select * from weather"); rs = stmt.executeQuery("select * from weather");
rs.next(); rs.next();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -133,8 +123,6 @@ public class NanoSecondTimestampRestfulTest { ...@@ -133,8 +123,6 @@ public class NanoSecondTimestampRestfulTest {
pstmt.setFloat(2, 12.34f); pstmt.setFloat(2, 12.34f);
pstmt.setInt(3, 55); pstmt.setInt(3, 55);
pstmt.executeUpdate(); pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} }
// when // when
...@@ -142,8 +130,6 @@ public class NanoSecondTimestampRestfulTest { ...@@ -142,8 +130,6 @@ public class NanoSecondTimestampRestfulTest {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery("select * from weather"); rs = stmt.executeQuery("select * from weather");
rs.next(); rs.next();
} catch (SQLException e) {
e.printStackTrace();
} }
// then // then
...@@ -156,26 +142,21 @@ public class NanoSecondTimestampRestfulTest { ...@@ -156,26 +142,21 @@ public class NanoSecondTimestampRestfulTest {
} }
@Before @Before
public void before() { public void before() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.execute("drop table if exists weather"); stmt.execute("drop table if exists weather");
stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); stmt.execute("create table weather(ts timestamp, temperature float, humidity int)");
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() throws SQLException {
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
try {
conn = DriverManager.getConnection(url); conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(); try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname); stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname + " precision 'ns'"); stmt.execute("create database if not exists " + dbname + " precision 'ns'");
stmt.execute("use " + dbname); stmt.execute("use " + dbname);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
......
...@@ -12,15 +12,13 @@ public class NullValueInResultSetJNITest { ...@@ -12,15 +12,13 @@ public class NullValueInResultSetJNITest {
Connection conn; Connection conn;
@Test @Test
public void test() { public void test() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from weather"); ResultSet rs = stmt.executeQuery("select * from weather");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) { while (rs.next()) {
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
...@@ -42,18 +40,12 @@ public class NullValueInResultSetJNITest { ...@@ -42,18 +40,12 @@ public class NullValueInResultSetJNITest {
stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)"); stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)");
stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')"); stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')");
stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')"); stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')");
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@After @After
public void after() { public void after() throws SQLException {
try {
if (conn != null) if (conn != null)
conn.close(); conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -12,7 +12,7 @@ public class NullValueInResultSetRestfulTest { ...@@ -12,7 +12,7 @@ public class NullValueInResultSetRestfulTest {
Connection conn; Connection conn;
@Test @Test
public void test() { public void test() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from weather"); ResultSet rs = stmt.executeQuery("select * from weather");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
...@@ -21,9 +21,6 @@ public class NullValueInResultSetRestfulTest { ...@@ -21,9 +21,6 @@ public class NullValueInResultSetRestfulTest {
Object value = rs.getObject(i); Object value = rs.getObject(i);
} }
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
...@@ -45,18 +42,12 @@ public class NullValueInResultSetRestfulTest { ...@@ -45,18 +42,12 @@ public class NullValueInResultSetRestfulTest {
stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)"); stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)");
stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')"); stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')");
stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')"); stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')");
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@After @After
public void after() { public void after() throws SQLException {
try {
if (conn != null) if (conn != null)
conn.close(); conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -20,7 +20,7 @@ public class PreparedStatementBatchInsertRestfulTest { ...@@ -20,7 +20,7 @@ public class PreparedStatementBatchInsertRestfulTest {
private Connection conn; private Connection conn;
@Test @Test
public void test() { public void test() throws SQLException {
// given // given
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
List<Object[]> rows = IntStream.range(0, 10).mapToObj(i -> { List<Object[]> rows = IntStream.range(0, 10).mapToObj(i -> {
...@@ -52,7 +52,6 @@ public class PreparedStatementBatchInsertRestfulTest { ...@@ -52,7 +52,6 @@ public class PreparedStatementBatchInsertRestfulTest {
} }
pstmt.executeBatch(); pstmt.executeBatch();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace();
Assert.fail(); Assert.fail();
} }
...@@ -64,35 +63,25 @@ public class PreparedStatementBatchInsertRestfulTest { ...@@ -64,35 +63,25 @@ public class PreparedStatementBatchInsertRestfulTest {
count++; count++;
} }
Assert.assertEquals(10, count); Assert.assertEquals(10, count);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Before @Before
public void before() { public void before() throws SQLException {
try {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname); stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname); stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname); stmt.execute("use " + dbname);
stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(groupId int)"); stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(groupId int)");
} catch (SQLException e) {
e.printStackTrace();
}
} }
@After @After
public void after() { public void after() throws SQLException {
try {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname); stmt.execute("drop database if exists " + dbname);
stmt.close(); stmt.close();
conn.close(); conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -19,8 +19,7 @@ public class QueryDataTest { ...@@ -19,8 +19,7 @@ public class QueryDataTest {
static String host = "127.0.0.1"; static String host = "127.0.0.1";
@Before @Before
public void createDatabase() { public void createDatabase() throws SQLException {
try {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
...@@ -36,9 +35,6 @@ public class QueryDataTest { ...@@ -36,9 +35,6 @@ public class QueryDataTest {
String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))"; String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))";
statement.executeUpdate(createTableSql); statement.executeUpdate(createTableSql);
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
...@@ -57,15 +53,11 @@ public class QueryDataTest { ...@@ -57,15 +53,11 @@ public class QueryDataTest {
} }
@After @After
public void close() { public void close() throws SQLException {
try {
if (statement != null) if (statement != null)
statement.close(); statement.close();
if (connection != null) if (connection != null)
connection.close(); connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
\ No newline at end of file
...@@ -15,19 +15,15 @@ public class ResultSetMetaShouldNotBeNullRestfulTest { ...@@ -15,19 +15,15 @@ public class ResultSetMetaShouldNotBeNullRestfulTest {
private Connection connection; private Connection connection;
@Test @Test
public void testExecuteQuery() { public void testExecuteQuery() throws SQLException {
// given // given
ResultSetMetaData metaData = null; ResultSetMetaData metaData;
int columnCount = -1; int columnCount;
// when // when
try {
Statement statement = connection.createStatement(); Statement statement = connection.createStatement();
metaData = statement.executeQuery("select * from weather").getMetaData(); metaData = statement.executeQuery("select * from weather").getMetaData();
columnCount = metaData.getColumnCount(); columnCount = metaData.getColumnCount();
} catch (SQLException e) {
e.printStackTrace();
}
// then // then
Assert.assertNotNull(metaData); Assert.assertNotNull(metaData);
...@@ -35,20 +31,17 @@ public class ResultSetMetaShouldNotBeNullRestfulTest { ...@@ -35,20 +31,17 @@ public class ResultSetMetaShouldNotBeNullRestfulTest {
} }
@Test @Test
public void testExecute() { public void testExecute() throws SQLException {
// given // given
ResultSetMetaData metaData = null; ResultSetMetaData metaData;
int columnCount = -1; int columnCount;
boolean execute = false; boolean execute;
// when // when
try {
Statement statement = connection.createStatement(); Statement statement = connection.createStatement();
execute = statement.execute("select * from weather"); execute = statement.execute("select * from weather");
metaData = statement.getResultSet().getMetaData(); metaData = statement.getResultSet().getMetaData();
columnCount = metaData.getColumnCount(); columnCount = metaData.getColumnCount();
} catch (SQLException e) {
e.printStackTrace();
}
// then // then
Assert.assertEquals(true, execute); Assert.assertEquals(true, execute);
...@@ -57,8 +50,7 @@ public class ResultSetMetaShouldNotBeNullRestfulTest { ...@@ -57,8 +50,7 @@ public class ResultSetMetaShouldNotBeNullRestfulTest {
} }
@Before @Before
public void before() { public void before() throws SQLException {
try {
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
stmt.execute("drop database if exists " + dbname); stmt.execute("drop database if exists " + dbname);
...@@ -66,21 +58,14 @@ public class ResultSetMetaShouldNotBeNullRestfulTest { ...@@ -66,21 +58,14 @@ public class ResultSetMetaShouldNotBeNullRestfulTest {
stmt.execute("use " + dbname); stmt.execute("use " + dbname);
stmt.execute("create table weather (ts timestamp, temperature float)"); stmt.execute("create table weather (ts timestamp, temperature float)");
stmt.close(); stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@After @After
public void after() { public void after() throws SQLException {
try {
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
stmt.execute("drop database if exists " + dbname); stmt.execute("drop database if exists " + dbname);
stmt.close(); stmt.close();
connection.close(); connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -17,8 +17,7 @@ public class SelectTest { ...@@ -17,8 +17,7 @@ public class SelectTest {
String host = "127.0.0.1"; String host = "127.0.0.1";
@Before @Before
public void createDatabaseAndTable() { public void createDatabaseAndTable() throws SQLException {
try {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
...@@ -32,10 +31,6 @@ public class SelectTest { ...@@ -32,10 +31,6 @@ public class SelectTest {
stmt.execute("create database if not exists " + dbName); stmt.execute("create database if not exists " + dbName);
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
stmt.close(); stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
...@@ -65,16 +60,12 @@ public class SelectTest { ...@@ -65,16 +60,12 @@ public class SelectTest {
} }
@After @After
public void close() { public void close() throws SQLException {
try {
if (connection != null) { if (connection != null) {
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
stmt.executeUpdate("drop database " + dbName); stmt.executeUpdate("drop database " + dbName);
stmt.close(); stmt.close();
connection.close(); connection.close();
} }
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -184,300 +184,248 @@ public class TimestampPrecisionInNanoInJniTest { ...@@ -184,300 +184,248 @@ public class TimestampPrecisionInNanoInJniTest {
} }
@Test @Test
public void canSelectFirstRowFromWeatherForSecondCol() { public void canSelectFirstRowFromWeatherForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select first(ts2) from " + ns_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select first(ts2) from " + ns_timestamp_db + ".weather");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanInDateTypeForFirstCol() { public void canQueryLargerThanInDateTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts > '" + date2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts > '" + date2 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts > '" + date2 + "'"); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts > '" + date2 + "'");
checkTime(timestamp3, rs); checkTime(timestamp3, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanInDateTypeForSecondCol() { public void canQueryLargerThanInDateTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 > '" + date2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 > '" + date2 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 > '" + date2 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 > '" + date2 + "'");
checkTime(timestamp3, rs); checkTime(timestamp3, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanInNumberTypeForFirstCol() { public void canQueryLargerThanInNumberTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts > '" + timestamp2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts > '" + timestamp2 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts > '" + timestamp2 + "'"); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts > '" + timestamp2 + "'");
checkTime(timestamp3, rs); checkTime(timestamp3, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanInNumberTypeForSecondCol() { public void canQueryLargerThanInNumberTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 > '" + timestamp2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 > '" + timestamp2 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 > '" + timestamp2 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 > '" + timestamp2 + "'");
checkTime(timestamp3, rs); checkTime(timestamp3, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanOrEqualToInDateTypeForFirstCol() { public void canQueryLargerThanOrEqualToInDateTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts >= '" + date2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts >= '" + date2 + "'");
checkCount(2l, rs); checkCount(2l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanOrEqualToInDateTypeForSecondCol() { public void canQueryLargerThanOrEqualToInDateTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 >= '" + date2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 >= '" + date2 + "'");
checkCount(2l, rs); checkCount(2l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanOrEqualToInNumberTypeForFirstCol() { public void canQueryLargerThanOrEqualToInNumberTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts >= '" + timestamp2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts >= '" + timestamp2 + "'");
checkCount(2l, rs); checkCount(2l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanOrEqualToInNumberTypeForSecondCol() { public void canQueryLargerThanOrEqualToInNumberTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 >= '" + timestamp2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 >= '" + timestamp2 + "'");
checkCount(2l, rs); checkCount(2l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanInDateTypeForFirstCol() { public void canQueryLessThanInDateTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts < '" + date3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts < '" + date3 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts < '" + date3 + "'"); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts < '" + date3 + "'");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanInDateTypeForSecondCol() { public void canQueryLessThanInDateTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 < '" + date3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 < '" + date3 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 < '" + date3 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 < '" + date3 + "'");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanInNumberTypeForFirstCol() { public void canQueryLessThanInNumberTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts < '" + timestamp3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts < '" + timestamp3 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts < '" + timestamp3 + "'"); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts < '" + timestamp3 + "'");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanInNumberTypeForSecondCol() { public void canQueryLessThanInNumberTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 < '" + timestamp3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 < '" + timestamp3 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 < '" + timestamp3 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 < '" + timestamp3 + "'");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanOrEqualToInDateTypeForFirstCol() { public void canQueryLessThanOrEqualToInDateTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "'");
checkCount(2l, rs); checkCount(2l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanOrEqualToInDateTypeForSecondCol() { public void canQueryLessThanOrEqualToInDateTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "'");
checkCount(2l, rs); checkCount(2l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanOrEqualToInNumberTypeForFirstCol() { public void canQueryLessThanOrEqualToInNumberTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "'");
checkCount(2l, rs); checkCount(2l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanOrEqualToInNumberTypeForSecondCol() { public void canQueryLessThanOrEqualToInNumberTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "'");
checkCount(2l, rs); checkCount(2l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryBetweenAndInDateTypeForFirstCol() { public void canQueryBetweenAndInDateTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "' AND ts > '" + date2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "' AND ts > '" + date2 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "' AND ts > '" + date2 + "'"); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "' AND ts > '" + date2 + "'");
checkTime(timestamp3, rs); checkTime(timestamp3, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryBetweenAndInDateTypeForSecondCol() { public void canQueryBetweenAndInDateTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "' AND ts2 > '" + date2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "' AND ts2 > '" + date2 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "' AND ts2 > '" + date2 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "' AND ts2 > '" + date2 + "'");
checkTime(timestamp3, rs); checkTime(timestamp3, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryBetweenAndInNumberTypeForFirstCol() { public void canQueryBetweenAndInNumberTypeForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "' AND ts > '" + timestamp2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "' AND ts > '" + timestamp2 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "' AND ts > '" + timestamp2 + "'"); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "' AND ts > '" + timestamp2 + "'");
checkTime(timestamp3, rs); checkTime(timestamp3, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryBetweenAndInNumberTypeForSecondCol() { public void canQueryBetweenAndInNumberTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "' AND ts2 > '" + timestamp2 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "' AND ts2 > '" + timestamp2 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "' AND ts2 > '" + timestamp2 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "' AND ts2 > '" + timestamp2 + "'");
checkTime(timestamp3, rs); checkTime(timestamp3, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryNotEqualToInDateTypeForSecondCol() { public void canQueryNotEqualToInDateTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <> '" + date3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <> '" + date3 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <> '" + date3 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <> '" + date3 + "'");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryNotEqualToInNumberTypeForSecondCol() { public void canQueryNotEqualToInNumberTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <> '" + timestamp3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <> '" + timestamp3 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <> '" + timestamp3 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <> '" + timestamp3 + "'");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryNotEqualInDateTypeForSecondCol() { public void canQueryNotEqualInDateTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 != '" + date3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 != '" + date3 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 != '" + date3 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 != '" + date3 + "'");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canQueryNotEqualInNumberTypeForSecondCol() { public void canQueryNotEqualInNumberTypeForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 != '" + timestamp3 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 != '" + timestamp3 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 != '" + timestamp3 + "'"); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 != '" + timestamp3 + "'");
checkTime(timestamp2, rs); checkTime(timestamp2, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canInsertTimestampWithNowAndNsOffsetInBothFirstAndSecondCol(){ public void canInsertTimestampWithNowAndNsOffsetInBothFirstAndSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(now + 1000b, now - 1000b, 128)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(now + 1000b, now - 1000b, 128)");
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather");
checkCount(3l, rs); checkCount(3l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canIntervalAndSlidingAcceptNsUnitForFirstCol(){ public void canIntervalAndSlidingAcceptNsUnitForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)"); ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)");
rs.next(); rs.next();
...@@ -486,13 +434,11 @@ public class TimestampPrecisionInNanoInJniTest { ...@@ -486,13 +434,11 @@ public class TimestampPrecisionInNanoInJniTest {
rs.next(); rs.next();
sum = rs.getLong(2); sum = rs.getLong(2);
Assert.assertEquals(128l, sum); Assert.assertEquals(128l, sum);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void canIntervalAndSlidingAcceptNsUnitForSecondCol(){ public void canIntervalAndSlidingAcceptNsUnitForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts2 >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)"); ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts2 >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)");
rs.next(); rs.next();
...@@ -501,8 +447,6 @@ public class TimestampPrecisionInNanoInJniTest { ...@@ -501,8 +447,6 @@ public class TimestampPrecisionInNanoInJniTest {
rs.next(); rs.next();
sum = rs.getLong(2); sum = rs.getLong(2);
Assert.assertEquals(128l, sum); Assert.assertEquals(128l, sum);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
...@@ -525,46 +469,38 @@ public class TimestampPrecisionInNanoInJniTest { ...@@ -525,46 +469,38 @@ public class TimestampPrecisionInNanoInJniTest {
} }
@Test @Test
public void willAutomaticallyFillToNsUnitWithZerosForFirstCol() { public void willAutomaticallyFillToNsUnitWithZerosForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "', '" + date1 + "', 127)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "', '" + date1 + "', 127)");
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "000000'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "000000'");
checkCount(1l, rs); checkCount(1l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void willAutomaticallyFillToNsUnitWithZerosForSecondCol() { public void willAutomaticallyFillToNsUnitWithZerosForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "', '" + date1 + "', 127)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "', '" + date1 + "', 127)");
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 = '" + date1 + "000000'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 = '" + date1 + "000000'");
checkCount(1l, rs); checkCount(1l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void willAutomaticallyDropDigitExceedNsDigitNumberForFirstCol() { public void willAutomaticallyDropDigitExceedNsDigitNumberForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "999999999', '" + date1 + "999999999', 127)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "999999999', '" + date1 + "999999999', 127)");
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "999999'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "999999'");
checkCount(1l, rs); checkCount(1l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void willAutomaticallyDropDigitExceedNsDigitNumberForSecondCol() { public void willAutomaticallyDropDigitExceedNsDigitNumberForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "999999999', '" + date1 + "999999999', 127)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "999999999', '" + date1 + "999999999', 127)");
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 = '" + date1 + "999999'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 = '" + date1 + "999999'");
checkCount(1l, rs); checkCount(1l, rs);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
} }
...@@ -15,7 +15,7 @@ public class UnsignedNumberJniTest { ...@@ -15,7 +15,7 @@ public class UnsignedNumberJniTest {
private static long ts; private static long ts;
@Test @Test
public void testCase001() { public void testCase001() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from us_table"); ResultSet rs = stmt.executeQuery("select * from us_table");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
...@@ -27,13 +27,11 @@ public class UnsignedNumberJniTest { ...@@ -27,13 +27,11 @@ public class UnsignedNumberJniTest {
Assert.assertEquals("2147483647", rs.getString(4)); Assert.assertEquals("2147483647", rs.getString(4));
Assert.assertEquals("9223372036854775807", rs.getString(5)); Assert.assertEquals("9223372036854775807", rs.getString(5));
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void testCase002() { public void testCase002() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from us_table"); ResultSet rs = stmt.executeQuery("select * from us_table");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
...@@ -46,8 +44,6 @@ public class UnsignedNumberJniTest { ...@@ -46,8 +44,6 @@ public class UnsignedNumberJniTest {
Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807L, rs.getLong(5)); Assert.assertEquals(9223372036854775807L, rs.getLong(5));
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
...@@ -140,14 +136,13 @@ public class UnsignedNumberJniTest { ...@@ -140,14 +136,13 @@ public class UnsignedNumberJniTest {
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() throws SQLException {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
ts = System.currentTimeMillis(); ts = System.currentTimeMillis();
try {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
conn = DriverManager.getConnection(url, properties); conn = DriverManager.getConnection(url, properties);
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
...@@ -157,19 +152,12 @@ public class UnsignedNumberJniTest { ...@@ -157,19 +152,12 @@ public class UnsignedNumberJniTest {
stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)"); stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)");
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)"); stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)");
stmt.close(); stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@AfterClass @AfterClass
public static void afterClass() { public static void afterClass() throws SQLException {
try {
if (conn != null) if (conn != null)
conn.close(); conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -16,7 +16,7 @@ public class UnsignedNumberRestfulTest { ...@@ -16,7 +16,7 @@ public class UnsignedNumberRestfulTest {
private static long ts; private static long ts;
@Test @Test
public void testCase001() { public void testCase001() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from us_table"); ResultSet rs = stmt.executeQuery("select * from us_table");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
...@@ -28,13 +28,11 @@ public class UnsignedNumberRestfulTest { ...@@ -28,13 +28,11 @@ public class UnsignedNumberRestfulTest {
Assert.assertEquals("2147483647", rs.getString(4)); Assert.assertEquals("2147483647", rs.getString(4));
Assert.assertEquals("9223372036854775807", rs.getString(5)); Assert.assertEquals("9223372036854775807", rs.getString(5));
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void testCase002() { public void testCase002() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from us_table"); ResultSet rs = stmt.executeQuery("select * from us_table");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
...@@ -47,8 +45,6 @@ public class UnsignedNumberRestfulTest { ...@@ -47,8 +45,6 @@ public class UnsignedNumberRestfulTest {
Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807L, rs.getLong(5)); Assert.assertEquals(9223372036854775807L, rs.getLong(5));
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
......
package com.taosdata.jdbc.cases; package com.taosdata.jdbc.cases;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.sql.*; import java.sql.*;
...@@ -12,7 +11,7 @@ public class UseNowInsertTimestampTest { ...@@ -12,7 +11,7 @@ public class UseNowInsertTimestampTest {
String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
@Test @Test
public void millisec() { public void millisec() throws SQLException {
try (Connection conn = DriverManager.getConnection(url)) { try (Connection conn = DriverManager.getConnection(url)) {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test"); stmt.execute("drop database if exists test");
...@@ -30,13 +29,11 @@ public class UseNowInsertTimestampTest { ...@@ -30,13 +29,11 @@ public class UseNowInsertTimestampTest {
assertEquals(0, nanos % 1000_000); assertEquals(0, nanos % 1000_000);
stmt.execute("drop database if exists test"); stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void microsec() { public void microsec() throws SQLException {
try (Connection conn = DriverManager.getConnection(url)) { try (Connection conn = DriverManager.getConnection(url)) {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test"); stmt.execute("drop database if exists test");
...@@ -53,13 +50,11 @@ public class UseNowInsertTimestampTest { ...@@ -53,13 +50,11 @@ public class UseNowInsertTimestampTest {
assertEquals(0, nanos % 1000); assertEquals(0, nanos % 1000);
stmt.execute("drop database if exists test"); stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void nanosec() { public void nanosec() throws SQLException {
try (Connection conn = DriverManager.getConnection(url)) { try (Connection conn = DriverManager.getConnection(url)) {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test"); stmt.execute("drop database if exists test");
...@@ -77,8 +72,6 @@ public class UseNowInsertTimestampTest { ...@@ -77,8 +72,6 @@ public class UseNowInsertTimestampTest {
assertTrue(nanos % 1000 != 0); assertTrue(nanos % 1000 != 0);
stmt.execute("drop database if exists test"); stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
} }
} }
} }
package com.taosdata.jdbc.cases; package com.taosdata.jdbc.confprops;
import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBDriver;
...@@ -19,8 +19,7 @@ public class BadLocaleSettingTest { ...@@ -19,8 +19,7 @@ public class BadLocaleSettingTest {
private static Connection conn; private static Connection conn;
@Test @Test
public void canSetLocale() { public void canSetLocale() throws SQLException {
try {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
...@@ -36,9 +35,6 @@ public class BadLocaleSettingTest { ...@@ -36,9 +35,6 @@ public class BadLocaleSettingTest {
stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); stmt.execute("create table weather(ts timestamp, temperature float, humidity int)");
stmt.executeUpdate("insert into weather values(1624071506435, 12.3, 4)"); stmt.executeUpdate("insert into weather values(1624071506435, 12.3, 4)");
stmt.close(); stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@BeforeClass @BeforeClass
...@@ -48,12 +44,8 @@ public class BadLocaleSettingTest { ...@@ -48,12 +44,8 @@ public class BadLocaleSettingTest {
} }
@AfterClass @AfterClass
public static void afterClass() { public static void afterClass() throws SQLException {
try {
if (conn != null) if (conn != null)
conn.close(); conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
\ No newline at end of file
...@@ -23,14 +23,12 @@ public class RestfulConnectionTest { ...@@ -23,14 +23,12 @@ public class RestfulConnectionTest {
} }
@Test @Test
public void createStatement() { public void createStatement() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select server_status()"); ResultSet rs = stmt.executeQuery("select server_status()");
rs.next(); rs.next();
int status = rs.getInt("server_status()"); int status = rs.getInt("server_status()");
assertEquals(1, status); assertEquals(1, status);
} catch (SQLException e) {
e.printStackTrace();
} }
} }
...@@ -359,13 +357,9 @@ public class RestfulConnectionTest { ...@@ -359,13 +357,9 @@ public class RestfulConnectionTest {
} }
@Test @Test
public void unwrap() { public void unwrap() throws SQLException {
try {
RestfulConnection restfulConnection = conn.unwrap(RestfulConnection.class); RestfulConnection restfulConnection = conn.unwrap(RestfulConnection.class);
Assert.assertNotNull(restfulConnection); Assert.assertNotNull(restfulConnection);
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
...@@ -374,9 +368,7 @@ public class RestfulConnectionTest { ...@@ -374,9 +368,7 @@ public class RestfulConnectionTest {
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() throws SQLException {
try {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
...@@ -386,20 +378,12 @@ public class RestfulConnectionTest { ...@@ -386,20 +378,12 @@ public class RestfulConnectionTest {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.execute("create database if not exists test"); stmt.execute("create database if not exists test");
} }
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
} }
@AfterClass @AfterClass
public static void afterClass() { public static void afterClass() throws SQLException {
try {
if (conn != null) if (conn != null)
conn.close(); conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ public class RestfulJDBCTest { ...@@ -14,7 +14,7 @@ public class RestfulJDBCTest {
private Connection connection; private Connection connection;
@Test @Test
public void testCase001() { public void testCase001() throws SQLException {
// given // given
String sql = "drop database if exists restful_test"; String sql = "drop database if exists restful_test";
// when // when
...@@ -38,7 +38,7 @@ public class RestfulJDBCTest { ...@@ -38,7 +38,7 @@ public class RestfulJDBCTest {
} }
@Test @Test
public void testCase002() { public void testCase002() throws SQLException {
// given // given
String sql = "create table weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)"; String sql = "create table weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)";
// when // when
...@@ -48,7 +48,7 @@ public class RestfulJDBCTest { ...@@ -48,7 +48,7 @@ public class RestfulJDBCTest {
} }
@Test @Test
public void testCase004() { public void testCase004() throws SQLException {
for (int i = 1; i <= 100; i++) { for (int i = 1; i <= 100; i++) {
// given // given
String sql = "create table t" + i + " using weather tags('beijing', '" + i + "')"; String sql = "create table t" + i + " using weather tags('beijing', '" + i + "')";
...@@ -60,7 +60,7 @@ public class RestfulJDBCTest { ...@@ -60,7 +60,7 @@ public class RestfulJDBCTest {
} }
@Test @Test
public void testCase005() { public void testCase005() throws SQLException {
int rows = 0; int rows = 0;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 1; j <= 100; j++) { for (int j = 1; j <= 100; j++) {
...@@ -99,7 +99,7 @@ public class RestfulJDBCTest { ...@@ -99,7 +99,7 @@ public class RestfulJDBCTest {
} }
@Test @Test
public void testCase007() { public void testCase007() throws SQLException {
// given // given
String sql = "drop database restful_test"; String sql = "drop database restful_test";
...@@ -110,51 +110,34 @@ public class RestfulJDBCTest { ...@@ -110,51 +110,34 @@ public class RestfulJDBCTest {
Assert.assertFalse(execute); Assert.assertFalse(execute);
} }
private int executeUpdate(Connection connection, String sql) { private int executeUpdate(Connection connection, String sql) throws SQLException {
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
return stmt.executeUpdate(sql); return stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} }
return 0;
} }
private boolean execute(Connection connection, String sql) { private boolean execute(Connection connection, String sql) throws SQLException {
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
return stmt.execute(sql); return stmt.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
} }
return false;
} }
private ResultSet executeQuery(Connection connection, String sql) { private ResultSet executeQuery(Connection connection, String sql) throws SQLException {
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
return statement.executeQuery(sql); return statement.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
} }
return null;
} }
@Before @Before
public void before() { public void before() throws SQLException {
try { connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata&httpKeepAlive=false");
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata");
} catch (SQLException e) {
e.printStackTrace();
}
} }
@After @After
public void after() { public void after() throws SQLException {
try {
if (connection != null) if (connection != null)
connection.close(); connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
...@@ -17,8 +17,7 @@ public class RestfulStatementTest { ...@@ -17,8 +17,7 @@ public class RestfulStatementTest {
private static Statement stmt; private static Statement stmt;
@Test @Test
public void executeQuery() { public void executeQuery() throws SQLException {
try {
ResultSet rs = stmt.executeQuery("show databases"); ResultSet rs = stmt.executeQuery("show databases");
Assert.assertNotNull(rs); Assert.assertNotNull(rs);
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
...@@ -29,15 +28,11 @@ public class RestfulStatementTest { ...@@ -29,15 +28,11 @@ public class RestfulStatementTest {
Assert.assertNotNull(rs.getString("name")); Assert.assertNotNull(rs.getString("name"));
} }
rs.close(); rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
public void executeUpdate() { public void executeUpdate() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
int affectRows = stmt.executeUpdate("create database " + dbName); int affectRows = stmt.executeUpdate("create database " + dbName);
Assert.assertEquals(0, affectRows); Assert.assertEquals(0, affectRows);
affectRows = stmt.executeUpdate("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); affectRows = stmt.executeUpdate("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
...@@ -46,17 +41,8 @@ public class RestfulStatementTest { ...@@ -46,17 +41,8 @@ public class RestfulStatementTest {
Assert.assertEquals(1, affectRows); Assert.assertEquals(1, affectRows);
affectRows = stmt.executeUpdate("drop database " + dbName); affectRows = stmt.executeUpdate("drop database " + dbName);
Assert.assertEquals(0, affectRows); Assert.assertEquals(0, affectRows);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void close() {
// test in AfterClass method
} }
@Test @Test
public void getMaxFieldSize() throws SQLException { public void getMaxFieldSize() throws SQLException {
Assert.assertEquals(16 * 1024, stmt.getMaxFieldSize()); Assert.assertEquals(16 * 1024, stmt.getMaxFieldSize());
...@@ -64,7 +50,6 @@ public class RestfulStatementTest { ...@@ -64,7 +50,6 @@ public class RestfulStatementTest {
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
public void setMaxFieldSize() throws SQLException { public void setMaxFieldSize() throws SQLException {
stmt.setMaxFieldSize(0); stmt.setMaxFieldSize(0);
stmt.setMaxFieldSize(-1); stmt.setMaxFieldSize(-1);
} }
...@@ -118,9 +103,8 @@ public class RestfulStatementTest { ...@@ -118,9 +103,8 @@ public class RestfulStatementTest {
} }
@Test @Test
public void execute() { public void execute() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
boolean isSelect = stmt.execute("create database if not exists " + dbName); boolean isSelect = stmt.execute("create database if not exists " + dbName);
Assert.assertEquals(false, isSelect); Assert.assertEquals(false, isSelect);
int affectedRows = stmt.getUpdateCount(); int affectedRows = stmt.getUpdateCount();
...@@ -143,15 +127,11 @@ public class RestfulStatementTest { ...@@ -143,15 +127,11 @@ public class RestfulStatementTest {
Assert.assertEquals(false, isSelect); Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount(); affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows); Assert.assertEquals(0, affectedRows);
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
public void getResultSet() { public void getResultSet() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
boolean isSelect = stmt.execute("create database if not exists " + dbName); boolean isSelect = stmt.execute("create database if not exists " + dbName);
Assert.assertEquals(false, isSelect); Assert.assertEquals(false, isSelect);
int affectedRows = stmt.getUpdateCount(); int affectedRows = stmt.getUpdateCount();
...@@ -187,14 +167,6 @@ public class RestfulStatementTest { ...@@ -187,14 +167,6 @@ public class RestfulStatementTest {
Assert.assertEquals(false, isSelect); Assert.assertEquals(false, isSelect);
affectedRows = stmt.getUpdateCount(); affectedRows = stmt.getUpdateCount();
Assert.assertEquals(0, affectedRows); Assert.assertEquals(0, affectedRows);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test
public void getUpdateCount() {
// already test in execute method
} }
@Test @Test
...@@ -239,23 +211,18 @@ public class RestfulStatementTest { ...@@ -239,23 +211,18 @@ public class RestfulStatementTest {
} }
@Test @Test
public void addBatch() { public void addBatch() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
stmt.addBatch("create database " + dbName); stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
stmt.addBatch("select * from " + dbName + ".weather"); stmt.addBatch("select * from " + dbName + ".weather");
stmt.addBatch("drop database " + dbName); stmt.addBatch("drop database " + dbName);
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
public void clearBatch() { public void clearBatch() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
stmt.clearBatch(); stmt.clearBatch();
stmt.addBatch("create database " + dbName); stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
...@@ -263,15 +230,11 @@ public class RestfulStatementTest { ...@@ -263,15 +230,11 @@ public class RestfulStatementTest {
stmt.addBatch("select * from " + dbName + ".weather"); stmt.addBatch("select * from " + dbName + ".weather");
stmt.addBatch("drop database " + dbName); stmt.addBatch("drop database " + dbName);
stmt.clearBatch(); stmt.clearBatch();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
public void executeBatch() { public void executeBatch() throws SQLException {
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
try {
stmt.addBatch("create database " + dbName); stmt.addBatch("create database " + dbName);
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
...@@ -283,20 +246,13 @@ public class RestfulStatementTest { ...@@ -283,20 +246,13 @@ public class RestfulStatementTest {
Assert.assertEquals(1, results[2]); Assert.assertEquals(1, results[2]);
Assert.assertEquals(Statement.SUCCESS_NO_INFO, results[3]); Assert.assertEquals(Statement.SUCCESS_NO_INFO, results[3]);
Assert.assertEquals(0, results[4]); Assert.assertEquals(0, results[4]);
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
public void getConnection() { public void getConnection() throws SQLException {
try {
Connection connection = stmt.getConnection(); Connection connection = stmt.getConnection();
Assert.assertNotNull(connection); Assert.assertNotNull(connection);
Assert.assertTrue(this.conn == connection); Assert.assertTrue(this.conn == connection);
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
...@@ -346,12 +302,8 @@ public class RestfulStatementTest { ...@@ -346,12 +302,8 @@ public class RestfulStatementTest {
} }
@Test @Test
public void isClosed() { public void isClosed() throws SQLException {
try {
Assert.assertEquals(false, stmt.isClosed()); Assert.assertEquals(false, stmt.isClosed());
} catch (SQLException e) {
e.printStackTrace();
}
} }
@Test @Test
...@@ -387,29 +339,21 @@ public class RestfulStatementTest { ...@@ -387,29 +339,21 @@ public class RestfulStatementTest {
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() throws SQLException {
try {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata", properties); conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata", properties);
stmt = conn.createStatement(); stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@AfterClass @AfterClass
public static void afterClass() { public static void afterClass() throws SQLException {
try {
if (stmt != null) if (stmt != null)
stmt.close(); stmt.close();
if (conn != null) if (conn != null)
conn.close(); conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册