在前面两篇 http://blog.matrix.org.cn/comments/icess/Weblog/use_derby_with_clob_and 文章中,我简单介绍了如何使用Java DB操作数据,今天发现一个关于关闭数据库的问题, 就是在调用前面例子中的关闭数据库代码时候总是抛出异常 ,后来到文档里面看看 ,原来在关闭数据库时候, Derby总是抛出异常,我还以为是我那个地方写错了呢?
以前例子中没有显示异常信息 是应为 在关闭数据库的方法中没有使用 打印异常信息的语句, 如下
public void disconnect() {
if(isConnected) {
String dbUrl = getDatabaseUrl();
dbProperties.put("shutdown", "true");
try {
DriverManager.getConnection(dbUrl, dbProperties);
} catch (SQLException ex) {
//ex.printStackTrace(); // 前面的例子没有该句, 如果加上该句,就会看的异常信息
}
isConnected = false;
}
}
所以,当大家看到下面的异常时候,不用担心 不是你的代码写错了,而是程序正确关闭数据库的提示(有点违背异常的设计初衷哦).
ERROR 08006: Database 'TestClob' shutdown.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.shutdownDatabaseException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
...........
21:10 补充:
使用Java DB的最佳实践
Recommended practices
When developing
Derby applications, create a single directory to hold your database or databases. Give this directory a unique name, to help you remember that:
- All databases exist within a system.
- System-wide properties affect the entire system, and persistent system-wide properties live in the system directory.
- You can boot all the databases in the system, and the boot-up times of all databases affect the performance of the system.
- You can preboot databases only if they are within the system. (Databases do not necessarily have to live inside the system directory, but keeping your databases there is the recommended practice.)
- Once you connect to a database, it is part of the current system and thus inherits all system-wide properties.
- Only one instance of Derby can run in a JVM at a single time, and only one instance of Derby should boot a database at one time. Keeping databases in the system directory makes it less likely that you would use more than one instance of Derby.
- The error log is located inside the system directory.
分享到:
相关推荐
试过了,可以用的。这次没有出现 数据库连接错误的问题
真正Java编写的数据库derby,驱动 derbyclient.jar
netbeans 开发 java web 初级
Java DB(英文全称data base,数据库)是依照某种数据模型组织起来并存放二...Java DB 是Oracle 支持的Apache Derby 开源数据库的发行版本。它通过JDBC 和Java EE API 支持标准的ANSI/ISO SQL。Java DB 包括在JDK 中。
db-derby-10.11.1.1-bin.zip,apache derby 相当于java db(derby)的完整版
Java6中自带的JavaDB(derby)数据库.pdf
Derby Developer's Guide. Purpose of this guide This guide explains how to use the core Derby technology and is for developers building Derby applications. It describes basic Derby concepts, such as ...
java derby数据库,包含jar文件和官方教程
真正的Derby新手教程,Derby安装,创建数据库,在Java程序中使用Derby 本人原创
Java嵌入式数据库的驱动包,详见JDK1.6的说明文档
关于Derby数据库的详尽描述 秒杀一切 让你学习Java的路上如鱼得水
Java for developer services
嵌入式Berkeley DB Java版与Derby技术研究.pdf
db-derby-10.11.1.1-src.zip,derby数据库源码
db-derby-10.6.2.1-bin.tar.gz
本文档详解了java6中derby内建的Derby数据库的使用及两种不同应用下解决方案。
derby+java对于derby数据库从安装到ij工具使用,最终创建数据表并在java中使用Jdbc初步应用
derby嵌入式数据库连接问题