简体   繁体   English

检查 MySQL RDMS 上是否存在表

[英]Checking if table exists on MySQL RDMS

I have here java code accessing mySQL database.我这里有 java 代码访问 mySQL 数据库。 It checks if table exists.它检查表是否存在。 The table is removed and does not exist, though code below is saying that the table exists.该表已被删除并且不存在,尽管下面的代码表示该表存在。

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;
  }
}

The method returns true that table exists.该方法返回 true 表示表存在。 Later on, the program catches that the table does not exists and crashes.稍后,程序捕获到该表不存在并崩溃。 What is the problem, please?请问是什么问题? The program runs on Tomcat 6.该程序在 Tomcat 6 上运行。

Restart the MySQL .重启MySQL (Kill the process if necessary). (必要时终止进程)。 That should work.那应该行得通。

There are sync issues in MySQL . MySQL中存在同步问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM