<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數(shù)據(jù)源小記

    ?

    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 訪問。。

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

    訪問代碼


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

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


    注意把mysql驅(qū)動拷到comcat common/lib下面..


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

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

    導(dǎo)航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動態(tài)語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評論

    主站蜘蛛池模板: 国产亚洲精品国产| 国产精品V亚洲精品V日韩精品 | 国产精品嫩草影院免费| 亚洲AV无码专区在线亚| 99热在线精品免费全部my| 亚洲欧美日韩一区二区三区| 毛片基地免费观看| 亚洲国产欧美国产综合一区 | 色噜噜综合亚洲av中文无码| 午夜精品射精入后重之免费观看 | 亚洲一区在线观看视频| 一个人免费观看视频www| 亚洲精品无码人妻无码| 日本免费v片一二三区| 国产成人亚洲综合在线| 亚洲美女在线国产| 久久综合九色综合97免费下载| 亚洲一区二区中文| 日本阿v免费费视频完整版| 亚洲人成电影网站色| 亚洲 无码 在线 专区| 中国videos性高清免费| 久久久久亚洲精品无码蜜桃| 免免费国产AAAAA片| 美女啪啪网站又黄又免费| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 国产精品永久免费视频| 亚洲国产精品SSS在线观看AV| 免费无遮挡无码永久视频| 2020亚洲男人天堂精品| 亚洲av日韩av欧v在线天堂| 99久久99这里只有免费的精品| 91精品国产亚洲爽啪在线影院| 手机在线看永久av片免费| 欧洲美女大片免费播放器视频| 亚洲精品中文字幕乱码三区| 午夜免费1000部| 免费无码午夜福利片| 亚洲精品视频在线| 青青草国产免费久久久91| 你懂的网址免费国产|