How can I retrieve MySQL temporary tables meta data within a single connection in JDBC?
And once again I have found an issue that I don't know how to fight with. Let's assume we have the following testing code:
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开发者_JAVA技巧 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);
}
Expected result is writing the T1
table meta data into the out
stream. But nothing happens, and it seems that getTables()
does not take into account the temporary tables. Don't know how I can resolve it... Is a work-around there? Your help is really very appreciated. Thanks a lot in advance.
MySQL sometimes does not provide support even for stupid things. There is no solution for the issue. Closed.
精彩评论