Apache Derby - 检查数据库已经创建? [英] Apache Derby - Check Database Already Created?

查看:264
本文介绍了Apache Derby - 检查数据库已经创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Apache Derby与Java(J2ME,但我不认为这会产生影响)是否有任何方法来检查数据库是否已经存在并包含表?

解决方案

我知道没有,除了几个工作,不像MySQL,我们有IF EXIST的设施。



你做的是,尝试连接到数据库,如果不能,它可能不存在。和成功的连接后,你可以做一个简单的选择,像SELECT count(*)FROM TABLE_NAME,知道表是否存在。你将依赖于异常。即使在Sun的官方示例中,我也看到了类似的工作。



在Oracle中,我们有字典表来了解数据库对象。



>好吧,我发现有一种方法知道表是否存在。尝试,SELECT tablename FROM SYSTABLES。它是用于检查表的存在,对于检查数据库,你可能需要做类似的事情,我上面解释。


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?

解决方案

I know of none, except few work around, unlike MySQL where we have that facility of IF EXIST.

What you do is, try to connect to the database, if couldn't its likely its not there. And after a successful connection, you can do a simple select, like SELECT count(*) FROM TABLE_NAME, to know whether the table exist or not. You would be depending on the exception. Even in an official example from Sun, I have seen the similar work around.

In Oracle we have dictionary tables to know about the database objects. I doubt if we have anything like that in Derby.

[Edited]

Well, I found that there is a way to know if the table exist. Try, SELECT tablename FROM SYSTABLES. It is for checking the existence of a table, for checking database you may need to do similar thing, I explained above.

这篇关于Apache Derby - 检查数据库已经创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆