change
This commit is contained in:
parent
d2620c993a
commit
a2e62fd3ed
|
@ -1,5 +1,6 @@
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
@ -8,53 +9,31 @@ import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class ConnectionTest extends BaseTest {
|
public class ConnectionTest {
|
||||||
static Connection connection = null;
|
private Connection connection;
|
||||||
static Statement statement = null;
|
private Statement statement;
|
||||||
static String dbName = "test";
|
private static String host = "127.0.0.1";
|
||||||
static String stbName = "st";
|
|
||||||
static String host = "localhost";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnection() throws SQLException {
|
public void testConnection() {
|
||||||
try {
|
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_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");
|
||||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
|
||||||
|
|
||||||
assertTrue(null != connection);
|
|
||||||
statement = connection.createStatement();
|
|
||||||
assertTrue(null != statement);
|
|
||||||
|
|
||||||
// try reconnect
|
|
||||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
statement.execute("create database if not exists " + dbName);
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||||
|
Assert.assertTrue(null != connection);
|
||||||
|
statement = connection.createStatement();
|
||||||
|
Assert.assertTrue(null != statement);
|
||||||
|
statement.close();
|
||||||
|
connection.close();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
return;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
assert false : "create database error: " + e.getMessage();
|
e.printStackTrace();
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!connection.isClosed()) {
|
|
||||||
if (!statement.isClosed()) {
|
|
||||||
statement.executeUpdate("drop database " + dbName);
|
|
||||||
statement.close();
|
|
||||||
}
|
|
||||||
connection.close();
|
|
||||||
Thread.sleep(10);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
assert false : "close connection error: " + e.getMessage();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue