sql - JavaDB - CREATE TABLE IF NOT EXISTS - how to? -


i'm trying create table using javadb (derby), if try add if not exists:

create table if not exists etc (id bigint primary key, title varchar(150)) 

i error:

java.sql.sqlsyntaxerrorexception: syntax error: encountered "not" @ line 1, column 17.

as remember works on mysql. syntax/simplest method check if table exists?

edit:

finally found 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 table name case sensitive if created using quotes "etc", , if not - name must upper case. according api documentation: "must match table name stored in database".

if not exists (select * sysobjects name='etc' , xtype='u') create table etc(    id bigint primary key, title varchar(150) ); 

it create table called etc if doesn't exist.

more of on here.

good luck


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -