之前是用 sql 去查,但會有 sql server / mysql / sqlite … 等多重 server 的問題,另一個較好的解法:
You can use the available meta data:
DatabaseMetaData meta = con.getMetaData();
ResultSet res = meta.getTables(null, null, "My_Table_Name",
new String[] {"TABLE"});
while (res.next()) {
System.out.println(
" "+res.getString("TABLE_CAT")
+ ", "+res.getString("TABLE_SCHEM")
+ ", "+res.getString("TABLE_NAME")
+ ", "+res.getString("TABLE_TYPE")
+ ", "+res.getString("REMARKS"));
}
See here for more details. Note also the caveats in the JavaDoc.