SQLServer2005+MySql+Oracle三种数据库连接池的配置(完结篇)

SQLServer2005+MySql+Oracle三种数据库连接池的配置(完结篇),第1张

概述//**本篇介绍了三种数据库SQLServer2005,MySql,Oracle三种数据库连接池的配置  *在配置前请确保tomcat的lib中已经导入所有的那种数据库驱动包  */ <?xml version='1.0' encoding='utf-8'?> <Context>     <!-- Default set of monitored resources -->     <Watche

//**本篇介绍了三种数据库sqlServer2005MysqLOracle三种数据库连接池的配置

 *在配置前请确保tomcatlib中已经导入所有的那种数据库驱动包

 */

<?xml version='1.0' enCoding='utf-8'?>

<Context>

    <!-- Default set of monitored resources -->

    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->

    <!--

    <Manager pathname="" />

    -->

 

    <!-- Uncomment this to enable Comet connection tacking (provIDes events

         on session expiration as well as webapp lifecycle) -->

    <!--

    <Valve classname="org.apache.catalina.valves.CometConnectionManagerValve" />

    -->

                  <!--MysqL数据库专用-->

              <Resource name="jdbc/MysqLds"

                                       auth="Container"

                                       type="javax.sql.DataSource"

                                       maxActive="100"

                                       maxIDle="30"

                                       maxWait="10000"

                                       username="root"

                                       password="jakeyouxiang"

                                       driverClassname="com.MysqL.jdbc.Driver"

                                       url="jdbc:MysqL://127.0.0.1/training"/>

                                      

               <!--sqlServer2005数据库专用-->

               <Resource name="jdbc/sqlds"

                               auth="Container"

                               type="javax.sql.DataSource"

                               maxActive="100"

                               maxIDle="30"

                               maxWait="10000"

                               username="sa"

                               password="jakeyouxiang"

                                       driverClassname="com.microsoft.sqlserver.jdbc.sqlServerDriver"

                               url="jdbc:sqlserver://127.0.0.1:1433;databasename=blog"/>

 

 

                                      

                  <!--MysqL数据库专用-->

               <Resource name="jdbc/oracleds"

                                       auth="Container"

                                       type="javax.sql.DataSource"

                                       maxActive="100"

                                       maxIDle="30"

                                       maxWait="10000"

                                       username="root"

                                       password="jakeyouxiang"

                                       driverClassname="oracle.jdbc.driver.OracleDriver"

                                       url="jdbc:oracle:thin:@127.0.0.1:1521:ora9"/>

                 

</Context>

 

 

//数据库得到Connection的程序

package database;

 

import java.sql.*;

import javax.naming.*;

import javax.sql.*;

import java.sql.*;

 

public class DataSource{

      

       public static Connection getConnection()throws Exception{

              //以下是应用线程池的方式

              Connection cn=null;

              DataSource ds=null;

              try{

                     Context con=new InitialContext();

                     //通过con得到数据源,最后的jdbc/MysqLds根据数据库的不同而有所不同

                     ds=(DataSource)con.lookup("java:comp/env/jdbc/MysqLds");

                     cn=ds.getConnection();

              }catch(Exception e){

                     e.printstacktrace();

              }    

              return cn;

       }

}

关键词:sqlServer2005线程池,MysqL线程池,Oracle线程池,各种数据库连接池,Content.xml

总结

以上是内存溢出为你收集整理的SQLServer2005+MySql+Oracle三种数据库连接池的配置(完结篇)全部内容,希望文章能够帮你解决SQLServer2005+MySql+Oracle三种数据库连接池的配置(完结篇)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1159925.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存