如何在 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() 似乎没有考虑临时表。不知道如何解决它...有解决方法吗?非常感谢您的帮助。预先非常感谢。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MySQL 有时甚至不提供对愚蠢的事情的支持。该问题没有解决方案。关闭。
MySQL sometimes does not provide support even for stupid things. There is no solution for the issue. Closed.