Ryan's Java world!

          something about Java and opensource!

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            51 Posts :: 25 Stories :: 59 Comments :: 0 Trackbacks

          在前面兩篇 http://blog.matrix.org.cn/comments/icess/Weblog/use_derby_with_clob_and??文章中,我簡(jiǎn)單介紹了如何使用Java DB操作數(shù)據(jù),今天發(fā)現(xiàn)一個(gè)關(guān)于關(guān)閉數(shù)據(jù)庫(kù)的問(wèn)題, 就是在調(diào)用前面例子中的關(guān)閉數(shù)據(jù)庫(kù)代碼時(shí)候總是拋出異常 ,后來(lái)到文檔里面看看 ,原來(lái)在關(guān)閉數(shù)據(jù)庫(kù)時(shí)候, Derby總是拋出異常,我還以為是我那個(gè)地方寫(xiě)錯(cuò)了呢?

          以前例子中沒(méi)有顯示異常信息 是應(yīng)為 在關(guān)閉數(shù)據(jù)庫(kù)的方法中沒(méi)有使用 打印異常信息的語(yǔ)句, 如下

          public void disconnect() {
          ??????? if(isConnected) {
          ??????????? String dbUrl = getDatabaseUrl();
          ??????????? dbProperties.put("shutdown", "true");
          ??????????? try {
          ??????????????? DriverManager.getConnection(dbUrl, dbProperties);
          ??????????? } catch (SQLException ex) {
          ??????????? ?//ex.printStackTrace();?? //?前面的例子沒(méi)有該句, 如果加上該句,就會(huì)看的異常信息
          ??????????? }
          ??????????? isConnected = false;
          ??????? }
          ??? }

          ?

          所以,當(dāng)大家看到下面的異常時(shí)候,不用擔(dān)心 不是你的代碼寫(xiě)錯(cuò)了,而是程序正確關(guān)閉數(shù)據(jù)庫(kù)的提示(有點(diǎn)違背異常的設(shè)計(jì)初衷哦).

          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 補(bǔ)充:

          使用Java DB的最佳實(shí)踐

          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.
          posted on 2006-04-17 20:38 冰雨 閱讀(857) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          JSF中文技術(shù)文摘
          主站蜘蛛池模板: 肃南| 屯昌县| 桦甸市| 当涂县| 荔浦县| 庄河市| 宣恩县| 黔西| 石景山区| 凭祥市| 安阳市| 资中县| 雅江县| 垦利县| 土默特左旗| 十堰市| 兴宁市| 江川县| 成武县| 鹤岗市| 同心县| 荣昌县| 杭州市| 西贡区| 兰考县| 和平区| 通山县| 晋州市| 阳新县| 大洼县| 兴文县| 读书| 义乌市| 九寨沟县| 台中市| 泰宁县| 固镇县| 台州市| 东阳市| 鸡东县| 黑河市|