<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    blogjava's web log

    blogjava's web log
    ...

    tomcat配置jndi數據源小記

    ?

    1.在server.xml中加入。
    這可以登陸后臺配置。。

    ? <!-- ??configure?DataSource.?Add?the?following?code?into?server.xml?? --> ?
    ?
    ?
    < ?Context? path? =?"?/test?" ??docBase? =?"test?" ??debug? =?"?0?" ?
    reloadable?
    =?"?true?" ??? > ?
    ?
    ?
    ???
    < ?Resource? name? =?"?jdbc/first?" ?
    ???????????????auth?
    =?"?Container?" ?
    ???????????????type?
    =?"?javax.sql.DataSource?" ??? /> ?
    ?
    ???
    < ?ResourceParams? name? =?"?jdbc/first?" ? > ?
    ?????
    < ?parameter? > ?
    ???????
    < ?name? > ?factory? </ ?name? > ?
    ???????
    < ?value? > ?org.apache.commons.dbcp.BasicDataSourceFactory? </ ?value? > ?
    ?????
    </ ?parameter? > ?
    ?
    ?????
    <!-- ??Maximum?number?of?dB?connections?in?pool.?Make?sure?you
    ?????????configure?your?mysqld?max_connections?large?enough?to?handle
    ?????????all?of?your?db?connections.?Set?to??0???for??no?limit.
    ??????????
    --> ?
    ?????
    < ?parameter? > ?
    ???????
    < ?name? > ?maxActive? </ ?name? > ?
    ???????
    < ?value? > ?100? </ ?value? > ?
    ?????
    </ ?parameter? > ?
    ?
    ?????
    <!-- ??Maximum?number?of?idle?dB?connections?to?retain?in?pool.
    ?????????Set?to??0???for??no?limit.
    ??????????
    --> ?
    ?????
    < ?parameter? > ?
    ???????
    < ?name? > ?maxIdle? </ ?name? > ?
    ???????
    < ?value? > ?30? </ ?value? > ?
    ?????
    </ ?parameter? > ?
    ?
    ?????
    <!-- ??Maximum?time?to?wait??for??a?dB?connection?to?become?available
    ?????????in?ms,?in??this??example??10??seconds.?An?Exception?is?thrown??if?
    ??????????this??timeout?is?exceeded.??Set?to??-?1??to?wait?indefinitely.
    ????????Maximum?time?to?wait??for??a?dB?connection?to?become?available
    ?????????in?ms,?in??this??example??10??seconds.?An?Exception?is?thrown??if?
    ??????????this??timeout?is?exceeded.??Set?to??-?1??to?wait?indefinitely.
    ??????????
    --> ?
    ?????
    < ?parameter? > ?
    ???????
    < ?name? > ?maxWait? </ ?name? > ?
    ???????
    < ?value? > ?10000? </ ?value? > ?
    ?????
    </ ?parameter? > ?
    ?
    ?????
    <!-- ??MySQL?dB?username?and?password??for??dB?connections??? --> ?
    ?????
    < ?parameter? > ?
    ??????
    < ?name? > ?username? </ ?name? > ?
    ??????
    < ?value? > ?dbuser? </ ?value? > ?
    ?????
    </ ?parameter? > ?
    ?????
    < ?parameter? > ?
    ??????
    < ?name? > ?password? </ ?name? > ?
    ??????
    < ?value? > ?1234? </ ?value? > ?
    ?????
    </ ?parameter? > ?
    ?
    ?????
    <!-- ??Class?name??for??mm.mysql?JDBC?driver?? --> ?
    ?????
    < ?parameter? > ?
    ????????
    < ?name? > ?driverClassName? </ ?name? > ?
    ????????
    < ?value? > ?com.mysql.jdbc.Driver? </ ?value? > ?
    ?????
    </ ?parameter? > ?
    ?
    ?????
    <!-- ??The?JDBC?connection?url??for??connecting?to?your?MySQL?dB.
    ?????????The?autoReconnect?=?true??argument?to?the?url?makes?sure?that?the
    ?????????mm.mysql?JDBC?Driver?will?automatically?reconnect??if??mysqld?closed?the
    ?????????connection.??mysqld?by??default??closes?idle?connections?after??8??hours.
    ??????????
    --> ?
    ?????
    < ?parameter? > ?
    ???????
    < ?name? > ?url? </ ?name? > ?
    ???????
    < ?value? > ?jdbc:mysql:?//?localhost:3306/test?autoReconnect=true </ value > ?
    ??????
    </ ?parameter? > ?
    ???
    </ ?ResourceParams? > ?
    ?
    ?
    </ ?Context? > ?

    在工程web-xml中加入以下代碼

    ????
    <resource-ref>
    ??????????
    <description>DB?Connection</description>
    ??????????
    <res-ref-name>jdbc/test</res-ref-name>
    ??????????
    <res-type>javax.sql.DataSource</res-type>
    ??????????
    <res-auth>Container</res-auth>
    ??????
    </resource-ref>


    jsp 訪問。。

    導包
    <%@?page?import="java.util.*"%>
    <%@?page?import="java.sql.*"%>
    <%@?page?import="javax.sql.*"%>
    <%@?page?import="javax.naming.*"%>
    <%@?page?import="com.mysql.jdbc.Connection"%>

    訪問代碼


    //建立數據庫連接
    Context?ctx?=?new?InitialContext();
    DataSource?ds?
    =(DataSource)ctx.lookup("java:comp/env/jdbc/test");
    con?
    =?ds.getConnection();
    //創建一個JDBC聲明
    stmt?=?con.createStatement();

    //有了連接。。就可以做很多事了。。


    注意把mysql驅動拷到comcat common/lib下面..


    目標:一天整理一點東西。。雖然簡單。。但記下來還是有好處的。。

    posted on 2006-05-12 10:29 record java and net 閱讀(605) 評論(0)  編輯  收藏 所屬分類: Jsp&&Web

    導航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動態語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評論

    主站蜘蛛池模板: 亚洲区小说区图片区| 四虎影院永久免费观看| 亚洲av永久无码精品网站| 中文在线免费视频| 亚洲人成无码网站| 99久久精品毛片免费播放| 国产∨亚洲V天堂无码久久久| 两个人日本WWW免费版| 久久精品国产亚洲麻豆| 午夜无码A级毛片免费视频| 中文字幕亚洲精品资源网| h视频在线观看免费完整版| 亚洲六月丁香婷婷综合| 全免费a级毛片免费看不卡| 美国毛片亚洲社区在线观看| 亚洲人成自拍网站在线观看| 亚洲精品综合一二三区在线| 成全在线观看免费观看大全| 久久亚洲高清观看| 十八禁无码免费网站| 亚洲国产美女精品久久| 免费激情视频网站| 一级做a爰片久久免费| 久久亚洲一区二区| 青青青免费国产在线视频小草| 亚洲人成电影网站免费| 亚洲伊人久久综合中文成人网| 日本不卡免费新一区二区三区| 亚洲国产日韩在线人成下载| 国产大片91精品免费观看男同| 中文在线观看免费网站| 亚洲国产韩国一区二区| 情侣视频精品免费的国产| aa在线免费观看| 亚洲日本久久久午夜精品| av在线亚洲欧洲日产一区二区| 99久久人妻精品免费一区| 亚洲色大18成人网站WWW在线播放| 亚洲第一黄片大全| a拍拍男女免费看全片| 成人午夜影视全部免费看|