ivaneeo's blog

          自由的力量,自由的生活。

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(34)

          我參與的團(tuán)隊(duì)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          Class.forName(props.getProperty("driver"));
          String url = props.getProperty("url");
          Connection con = DriverManager.getConnection(url, props);
          //        showWarnings(con.getWarnings());
          initLanguage(con);
          return con;

          上面的Connection類的方法getWarnings檢索調(diào)用這個(gè)Connection對象的第一個(gè)警告.如果有多個(gè)可以用getNextWarning方法得到.

          public void showWarnings(SQLWarning w) {
            while (w != null) {
              System.out.println(w.getMessage());
              w = w.getNextWarning();
            }
          }

          private void initLanguage(Connection con) throws SQLException {
          Statement stmt = con.createStatement();

          stmt.executeUpdate("set LANGUAGE 'us_english'");
          stmt.close();
          }
          上面函數(shù)顯示了一個(gè)比較簡單的調(diào)用語句的方法.

          這里是使用的屬性文件注冊.屬性文件如下:
          --------------------------------------------------------------------
          #屬性文件connection.properties.tmpl
          #
          # The URL of the server to which you want to connect
          #
          driver=net.sourceforge.jtds.jdbc.Driver
          url=jdbc:jtds:sqlserver://localhost/dbname
          USER=XXXX
          PASSWORD=YYYY
          SERVERNAME=localhost
          PORTNUMBER=1433
          DATABASENAME=dbname
          XAEMULATION=true

          #
          # TDS Version
          #

          #
          # Use this for MS SQL Server 6.5+
          #
          #TDS=4.2

          #
          # Use this for Sybase 10+
          #
          #TDS=5.0

          #
          # Use this for MS SQL Server 7.0+
          #
          #TDS=7.0

          #
          # Use this for MS SQL Server 2000 (default)
          #
          TDS=8.0
          --------------------------------------------------------------------

          讀入屬性文件如下:
          String CONNECTION_PROPERTIES = "conf/connection.properties";
          File propFile = new File(fileName);
          if (!propFile.exists()) {
            fail("Connection properties not found (" + propFile + ").");
          }
          try {
          Properties props = new Properties();
          props.load(new FileInputStream(propFile));
          return props;
          }
          catch (IOException e) {
          throw new RuntimeException(e.getMessage());
          }
          這里是fail函數(shù)是使用了junit的fail方法,表示測試失敗.
          posted on 2005-08-04 21:13 ivaneeo 閱讀(624) 評論(0)  編輯  收藏 所屬分類: java魔力
          主站蜘蛛池模板: 崇明县| 那坡县| 航空| 吴川市| 招远市| 永定县| 额敏县| 霍林郭勒市| 高淳县| 师宗县| 普陀区| 泰州市| 溆浦县| 邹平县| 张掖市| 镇沅| 基隆市| 阿克苏市| 杂多县| 绥宁县| 开封县| 依兰县| 鸡西市| 涿州市| 前郭尔| 芒康县| 洞口县| 彰武县| 视频| 岳阳市| 伊金霍洛旗| 宁蒗| 长泰县| 普格县| 靖江市| 永丰县| 毕节市| 陆良县| 勐海县| 嘉峪关市| 临西县|