方法1、
java.sql.Connection con = getYourConnection();
ResultSet rs = con.getMetaData().getTables(null, null, "yourTable", null );
if (rs.next())
{
//yourTable exist
}else
{
//yourTable not exist
}
方法二、
Connection conn = null;
DatabaseMetaData dbmd = null;
ResultSet rs = null;
try{
conn = getConnectionSource();
dbmd = conn.getMetaData();
rs = dbmd.getTables(null,null,null,new String[]{"TABLE"});
while(rs.next()){
String tableName = rs.getString("TABLE_NAME");
System.out.println("tablename:"+tableName);
}
}catch(Exception ex){
throw ex;
}finally{
closeConnection(conn,rs,null);
}
dbmd.getTables(null,null,null,new String[]{"TABLE"});这句是关键,可查看JAVA API说明了解详细信息,方法一,二的这句可组合在一起写dbmd.getTables(null,null,tableName,new String[]{"TABLE"});通过变换这句可以得到数据库表的注释等相关信息(还是看API)