摘要:Java 取得 MySQL的table列表
Mysql 語法 :show tables;
public List<String> queryTables()
{
List<String> queue_list = new ArrayList<String>();
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, user, password);
DatabaseMetaData dbm = conn.getMetaData();
String[] types = {"TABLE"};
rs = dbm.getTables(null,null,"%",types);
while (rs.next()) {
String table = rs.getString("TABLE_NAME");
queue_list.add(table);
}
} catch (Exception ex) {
log.error(ex);
} finally {
rs.close();
pstmt.close();
conn.close();
}
return queue_list;
}