Using Apache Derby with Java (J2ME, however i don't believe that is important) can there be in whatever way of checking if your database already is available and consists of a table?



I understand of none, except couple of deal with, unlike MySQL where we've that facility of IF EXIST.

That which you do is, attempt to connect with the database, if could not its potential it is not there. And following a effective connection, you are able to perform a simple choose, like Choose count(*) FROM TABLE_Title, to understand if the table exist or otherwise. You'd be with respect to the exception. Even just in the official example from Sun, I've come across the same deal with.

In Oracle we've dictionary tables to understand about the database objects. I doubt when we have anything like this in Derby.


Well, I discovered that there's a method to determine if the table exist. Try, Choose tablename FROM SYSTABLES. It's for checking the presence of a table, for checking database you may want to do similar factor, I described above.

Adeel, you might use Connection.getMetaData to come back a DatabaseMetaData object, then make use of the getTables, after you have the bond towards the database obviously. It has the benefit of employed by any database having a JDBC driver worth it's salt.

For checking when the database is available, if you work with Derby within the embedded way, or even the server is on a single machine, you can see if the folder for that database is available. Is a little kludgy though. I'd do as Adeel indicates and then try to connect, catching the exception when not there.

I recommend obtaining the DatabaseMetaData object, then while using getTables(null, null, null, new String[]) method from this, which returns a ResultSet. Make use of the next() approach to the ResultSet, which returns a boolean, to check if any tables exist. Whether it tests true, you've tables around. False, and also the database is empty.