提交 bbf6640d 编写于 作者: Z zyyang

change

上级 5f80b8e7
......@@ -10,6 +10,7 @@ import java.util.Properties;
public class AuthenticationTest {
// private static final String host = "127.0.0.1";
private static final String host = "master";
private static final String user = "root";
private static final String password = "123456";
......@@ -17,7 +18,20 @@ public class AuthenticationTest {
@Test
public void test() {
try (Statement stmt = conn.createStatement()) {
// change password
try {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata");
Statement stmt = conn.createStatement();
stmt.execute("alter user " + user + " pass '" + password + "'");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
// use new to login and execute query
try {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password);
Statement stmt = conn.createStatement();
stmt.execute("show databases");
ResultSet rs = stmt.getResultSet();
ResultSetMetaData meta = rs.getMetaData();
......@@ -30,28 +44,24 @@ public class AuthenticationTest {
} catch (SQLException e) {
e.printStackTrace();
}
}
@Before
public void before() {
// change password back
try {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
Properties props = new Properties();
props.setProperty(TSDBDriver.PROPERTY_KEY_USER, user);
props.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, password);
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test", props);
} catch (SQLException | ClassNotFoundException e) {
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password);
Statement stmt = conn.createStatement();
stmt.execute("alter user " + user + " pass 'taosdata'");
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@After
public void after() {
@Before
public void before() {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册