重新探索自我

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

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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("沒有匹配的環(huán)境!");
          ??DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/blogdb");
          ??if( ds == null ) throw new Exception("沒有匹配的數(shù)據(jù)庫!");
          ??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開發(fā)

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 济源市| 健康| 卢湾区| 宜良县| 沈丘县| 壶关县| 石柱| 安徽省| 麻江县| 巴塘县| 高平市| 多伦县| 密云县| 军事| 阳原县| 凤山市| 石林| 玛沁县| 基隆市| 阿克苏市| 达州市| 汉中市| 邵东县| 满城县| 德州市| 扎兰屯市| 那曲县| 嘉定区| 蒙山县| 土默特左旗| 澎湖县| 莱阳市| 华阴市| 林西县| 平顶山市| 湄潭县| 阿鲁科尔沁旗| 泾阳县| 娱乐| 宝坻区| 深水埗区|