@Test
|
public void test() throws SQLException {
|
String url = "jdbc:mariadb://localhost:3306?user=user&password=password";
|
Connection con = DriverManager.getConnection(url);
|
|
execute(con, "DROP DATABASE IF EXISTS test");
|
execute(con, "CREATE DATABASE test");
|
execute(con, "USE test");
|
execute(con, "CREATE TABLE IF NOT EXISTS t0(c0 DECIMAL UNSIGNED)");
|
execute(con, "INSERT INTO t0 VALUES(23987)");
|
|
Statement stmt = con.createStatement();
|
if (stmt.execute("SELECT * FROM t0")) {
|
ResultSet rs = stmt.getResultSet();
|
ResultSetMetaData rsMetaData = rs.getMetaData();
|
int count = rsMetaData.getColumnCount();
|
StringBuffer sb = new StringBuffer();
|
|
for (int i = 1; i <= count; i++) {
|
sb.append("* " + rsMetaData.getColumnTypeName(i) + " *");
|
}
|
System.out.println(sb);
|
}
|
}
|
|
public void execute(Connection con, String sql) {
|
try {
|
Statement statement = con.createStatement();
|
statement.execute(sql);
|
statement.close();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
}
|