How to check if a table exists using jdbc java

1

How to check if a table exists in jdbc using Sqlite3?

    
asked by anonymous 25.04.2016 / 02:25

1 answer

3

You can use the available metadata:

  DatabaseMetaData meta = con.getMetaData();
  ResultSet res = meta.getTables(null, null, "My_Table_Name", 
     new String[] {"TABLE"});
  while (res.next()) {
     System.out.println(
        "   "+res.getString("TABLE_CAT") 
       + ", "+res.getString("TABLE_SCHEM")
       + ", "+res.getString("TABLE_NAME")
       + ", "+res.getString("TABLE_TYPE")
       + ", "+res.getString("REMARKS")); 
  }

See more details here . Note the warnings at Javadoc .

    
25.04.2016 / 03:41