如何配置TOMCAT+ORACLE连接池?

发布时间:2016-12-10 5:56:58 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"如何配置TOMCAT+ORACLE连接池?",主要涉及到如何配置TOMCAT+ORACLE连接池?方面的内容,对于如何配置TOMCAT+ORACLE连接池?感兴趣的同学可以参考一下。

可以通过配置DBCP连接池,在Server.xml中加入    <Context  path="/demo"  docBase="D:/demo">                    <Resource  name="jdbc/demo"  scope="Shareable"  type="javax.sql.DataSource"/>                    <ResourceParams  name="jdbc/demo">                            <parameter>                                    <name>factory</name>                                    <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>                            </parameter>                                        <!--  DBCP  database  connection  settings  -->                            <parameter>                                    <name>url</name>                                    <value>jdbc:oracle:thin:@10.0.0.10:1521:demo</value>                            </parameter>                            <parameter>                                    <name>driverClassName</name>                                    <value>oracle.jdbc.driver.OracleDriver</value>                            </parameter>                            <parameter>                                    <name>username</name>                                    <value>demo</value>                            </parameter>                            <parameter>                                    <name>password</name>                                    <value>demo</value>                            </parameter>                                        <!--  DBCP  connection  pooling  options  -->                            <parameter>                                    <name>maxWait</name>                                    <value>3000</value>                            </parameter>                            <parameter>                                    <name>maxIdle</name>                                    <value>100</value>                            </parameter>                            <parameter>                                    <name>maxActive</name>                                    <value>10</value>                            </parameter>                    </ResourceParams>            </Context> 一样,是配置web服务器,在你用得到的时候取出来就行了                InitialContext  initContext  =  new  InitialContext();                String  dsName  =  "java:comp/env/jdbc/demo";                DataSource  ds  =  null;                try  {                    ds  =  (DataSource)  initContext.lookup(dsName);                }                catch  (NameNotFoundException  nfex)  {                    dsName  =  "jdbc/demo";                    ds  =  (DataSource)  initContext.lookup(dsName);                }                if  (ds  !=  null)  {                    con  =  ds.getConnection();                }

上一篇:突然觉得一个感情空虚的人是多么的痛苦?
下一篇:kitchen's memory of Singapore

相关文章

相关评论