Chris wrote:
MySQL has a really nice syntax for creating tables if they don't exist
already:
CREATE TABLE IF NOT EXISTS foo (...)
How can I get the same functionality in Derby? I haven't been able to
figure out the SQL command to check for the existence of a table.
You could catch the SQLException and ignore it, e.g.
try {
s.executeUpdate("CREATE TABLE FOO (I INT)");
} catch (SQLException se) {
if (!se.getSQLState().equals("X0Y32"))
throw se;
}
alternately you can use the DatabaseMetaData to see if the table is there
DatabaseMetaData dmd = conn.getMetaData();
ResultSet rs = dmd.getTables(null,"APP", "FOO",null);
if (!rs.next()) {
s.executeUpdate("CREATE TABLE FOO (I INT)");
}