检查MySQL RDMS上是否存在表

时间:2011-05-25 23:54:27

标签: java mysql sql

我这里有访问mySQL数据库的java代码。它检查表是否存在。该表已删除但不存在,但下面的代码表示该表存在。

private Boolean tableExists(String globalId) {
  // schema Test
  DBResult result =  db.selectQuery("SELECT table_name 
                                       FROM information_schema.tables 
                                      WHERE table_schema = '"+schema+"' 
                                        AND table_name = " + "\'" + "category_"+globalId.split("-")[1]+ "\'"+";");
  if(result.getRowCount() > 0) {
    logger.info(" Table exist "+globalId);
    return true; 
  } else {
    logger.info("table does not exist "+ globalId);
    return false;
  }
}

该方法返回true,表存在。稍后,该程序捕获该表不存在并崩溃。请问是什么问题?该程序在Tomcat 6上运行。

1 个答案:

答案 0 :(得分:1)

重新启动MySQL。 (如有必要,请杀死该过程)。这应该有用。

MySQL中存在同步问题。

相关问题