Apache Derby - Check Database Already Created?

前端 未结 3 468
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 18:14

Using Apache Derby with Java (J2ME, but I don\'t think that makes a difference) is there any way of checking if a database already exists and contains a table?

3条回答
  •  清歌不尽
    2021-01-02 18:53

    Adeel, you could also use Connection.getMetaData to return a DatabaseMetaData object, then use the getTables, once you have the connection to the database of course. This has the advantage of working for any database with a JDBC driver worth it's salt.

    For checking if the database exists, if you are using Derby in the embedded way, or the server is on the same machine, you could check if the folder for the database exists. Is a bit kludgy though. I would do as Adeel suggests and try to connect, catching the exception if it's not there.

提交回复
热议问题