I'm trying to create table using JavaDB (Derby), but if I try to add IF NOT EXISTS:
CREATE TABLE IF NOT EXISTS etc (ID BIGINT PRIMARY KEY, title VARCHAR(150))
I get the error:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "NOT" at line 1, column 17.
As I remember it works on MySQL. What is the syntax/simplest method to check if table exists?
EDIT:
Finally I found the solution:
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getTables(null, "APP", "ETC", null);
if (rs.next()) {
System.out.println("Table " + rs.getString(3) + " exists");
}
I noticed that table name is case sensitive if it is created with using quotes "etc", and if not - the name must be upper case. According API documentation: "must match the table name as it is stored in the database".