日期:2014-05-19 浏览次数:20690 次
try { Statement stmt = connect.createStatement(); stmt.executeQuery( "select count(*) from yourTable "); } catch(SQLException e) { System.out.print( "not exits "+ e.getMessage()); }
------解决方案--------------------
//name 表名 public boolean HasTable(String name) { //判断某一个表是否存在 boolean result = false; try { DatabaseMetaData meta = sqlConn.getMetaData();//sqlConn 数据库连接 ResultSet set = meta.getTables (null, null, name, null); while (set.next()) { result = true; } } catch (Exception e) { System.err.println(e); e.printStackTrace (); } return result; }