提交 bbf6640d 编写于 作者: Z zyyang

change

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