0
我再次發現了一個我不知道如何與之抗爭的問題。假設我們有以下的測試代碼:如何在JDBC中的單個連接中檢索MySQL臨時表元數據?
private static final String CREATE_TEMPORARY_TABLE =
"CREATE TEMPORARY TABLE T1 (\n" +
"\tA FLOAT(4, 1),\n" +
"\tB FLOAT(5, 2),\n" +
"\tC FLOAT,\n" +
"\tD INTEGER\n" +
") ENGINE = MEMORY;";
private final String[] SHOW_TABLE_TYPES = new String[] {
//"TABLE",
"VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM"
};
private void createTemporaryTable(Connection connection) throws SQLException {
final PreparedStatement statement = connection.prepareStatement(CREATE_TEMPORARY_TABLE);
statement.execute();
statement.close();
}
private void showTables(Connection connection) throws SQLException {
final ResultSet set = connection.getMetaData().getTables(null, null, null, SHOW_TABLE_TYPES);
while (set.next()) {
out.println(format("%s %s %s %s %s",
set.getString("TABLE_CAT"),
set.getString("TABLE_SCHEM"),
set.getString("TABLE_NAME"),
set.getString("TABLE_TYPE"),
set.getString("REMARKS")
));
}
set.close();
}
@Override
public void test(Connection connection) throws SQLException {
createTemporaryTable(connection);
showTables(connection);
}
預期的結果是寫T1
表元數據爲out
流。但沒有任何反應,而且似乎getTables()
沒有考慮到臨時表。不知道我可以如何解決它...是一個解決方法嗎?你的幫助真的很感激。提前致謝。