快速配置tomcat连接池
以oracle为例
1、下载oracle驱动包、如class14.jar
2、将驱动包拷贝到tomcat_home\lib或者webapp\WEB-INF\lib其区别是针对的作用域不同,前者对于所有web程序、后者对于当前webapp
3、添加webapp\WebRoot\META-INF\context.xml文件
context.xml文件内容
<?xml version="1.0" encoding="UTF-8"?> <Context> <Resource name="jdbc/cms" auth="Container" type="javax.sql.DataSource" driverClassname="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@127.0.0.1:1521:bjsxt" username="cms" password="cms" maxActive="5" maxIdle="2" maxWait="-1"/> </Context>4、要了解的是
MIN_SIZE是初始化时的连接数
MAX_SIZE空闲时最大连接数
5、创建连接类连接方法
Class DB{ public static Connection getConnectionFromPool() { Connection conn = null; Context context = null; DataSource ds = null; try { context = new InitialContext(); ds = (DataSource) context.lookup("java:comp/env/jdbc/cms"); conn = ds.getConnection(); } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } }
相关推荐
FanErZong 2020-07-18
86284851 2020-06-16
85427617 2020-06-13
88291846 2020-06-07
86284851 2020-02-28
81510598 2020-01-08
88291846 2020-01-04
86284851 2019-12-28
detianlangzi 2014-06-17
85427617 2019-12-24
87497118 2019-11-28
82981634 2014-03-25
85427617 2015-08-19
81510598 2019-11-11
86284851 2019-11-08
doITwhat 2015-09-11