ucas
ucas

Reputation: 487

Checking if table exists on MySQL RDMS

I have here java code accessing mySQL database. 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. Later on, the program catches that the table does not exists and crashes. What is the problem, please? The program runs on Tomcat 6.

Upvotes: 1

Views: 1212

Answers (1)

Sachin
Sachin

Reputation: 18777

Restart the MySQL. (Kill the process if necessary). That should work.

There are sync issues in MySQL.

Upvotes: 1

Related Questions