重新探索自我

              客觀條件受制于人,并不足懼。重要的是,我們擁有選擇的自由,可以對現實環境積極回應,
              為生命負責,為自己創造有利的機會,做一個“真正”操之在我的人!

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            3 隨筆 :: 10 文章 :: 5 評論 :: 0 Trackbacks


          配置文件:
          <Context path="/apple" docBase="D:\workspace\bolg\webdoc"
          ???????? privileged="true" antiResourceLocking="false" antiJARLocking="false">
          ?<Resource name="jdbc/blogdb" auth="Container"
          ??? type="javax.sql.DataSource"
          ??? maxActive="100" maxIdle="30" maxWait="10000"
          ??? username="root" password=""
          ??? driverClassName="com.mysql.jdbc.Driver"
          ??? url="jdbc:mysql://localhost:3306/blogdb?autoReconnect=true"/>
          </Context>

          調用方式:
          ?Context ctx = null ;
          ?Connection conn = null;
          ?Statement stmt = null ;
          ?ResultSet rs = null;
          ?try{
          ??ctx = new InitialContext();
          ??if( ctx == null) throw new Exception("沒有匹配的環境!");
          ??DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/blogdb");
          ??if( ds == null ) throw new Exception("沒有匹配的數據庫!");
          ??conn = ds.getConnection();
          ??stmt = conn.createStatement();
          ??rs = stmt.executeQuery(" select * from tbl_blog");
          ??while(rs.next()){
          ???out.print(rs.getString(2));
          ??}
          ??
          ?}catch(Exception e){
          ??e.printStackTrace();
          ?}finally{
          ??if(rs!=null) rs.close();
          ??if(stmt!=null) stmt.close();
          ??if(conn!=null) conn.close();
          ??if(ctx!=null) ctx.close();
          ?}



          posted on 2006-10-17 12:32 蔣利文 閱讀(1007) 評論(0)  編輯  收藏 所屬分類: J2EE開發

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 南雄市| 宁化县| 名山县| 黄山市| 凤阳县| 阿克苏市| 昌江| 克什克腾旗| 休宁县| 东莞市| 太原市| 宁海县| 普宁市| 丹寨县| 稻城县| 富顺县| 依安县| 龙海市| 博罗县| 大英县| 平江县| 海晏县| 瓮安县| 白玉县| 扬中市| 永吉县| 达日县| 西峡县| 桐乡市| 揭西县| 平遥县| 随州市| 武安市| 石棉县| 融水| 涟源市| 宁远县| 泸水县| 丘北县| 庄浪县| 黄骅市|