views:

30

answers:

1

hello, We created a java application which uses the JavaDB database in Netbeans IDE. We want the program to check every time it starts if the database's tables have already been created, and otherwise create them. How do we do that? thanx

+1  A: 

I use :

DatabaseMetaData metas;
ResultSet tables;
Statement stat;

m_connexion = DriverManager.getConnection("jdbc:derby:mybase;create=true");
metas = m_connexion.getMetaData();
stat = m_connexion.createStatement();
tables = metas.getTables(m_connexion.getCatalog(), null, "MYTABLE", null);
if (!tables.next())
  stat.execute(
    "CREATE TABLE APP.MYTABLE (" // etc.

... and it's work for me.

Istao