300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > java sqlserver 连接池_java同时配置多个数据库连接池

java sqlserver 连接池_java同时配置多个数据库连接池

时间:2020-09-12 19:34:15

相关推荐

java sqlserver 连接池_java同时配置多个数据库连接池

/coderworld/p/database-connectionpool.html 阅读目录 引言 设计 使用 代码 测试 回到顶部 引言 池化技术在Java中应用的很广泛,简而论之,使用对象池存储某个实例数受限制的实例,开发者从对象池中获取实例,使用完之后再换回对

java配置数据库连接池以mysql和sqlserver为例

配置tomcat下面的content.xml

auth="Container"

type="javax.sql.DataSource"

driverClassName="com.mysql.jdbc.Driver"

url="jdbc:mysql://localhost:3306/com?useUnicode=true&characterEncoding=UTF-8"

username="root"

password="root"

maxActive="100"

maxIdle="2"

maxWait="10000" />

removeAbandoned

true

removeAbandonedTimeout

60

logAbandoned

true

auth="Container"

type="javax.sql.DataSource"

driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"

url="jdbc:microsoft:sqlserver://localhost:1433;databaseName=fashion"

username="sa"

password=""

maxActive="100"

maxIdle="30"

maxWait="10000" />

removeAbandoned

true

removeAbandonedTimeout

60

logAbandoned

true

-->

WEB-INF/web.xml

设置项目目录下面的WEB-INF下面的web.xml文件在里面加入META-INF文件下新建context.xml,里面的内容为:

DB Connection

jdbc/mysql

javax.sql.DataSource

Container

DB

jdbc/sqlserver

javax.sql.DataSource

Container

测试文件

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

DataSource ds = null;

InitialContext ctx=new InitialContext();

ds=(DataSource)ctx.lookup("java:comp/env/jdbc/sqlserver");

Connection conn = ds.getConnection();

%>

Statement stmt=conn.createStatement();

String sql_gun="select * from sm_t_salesheet" ;

ResultSet rs_gun=stmt.executeQuery(sql_gun);

while(rs_gun.next())

{

%>

}

rs_gun.close();

stmt.close();

%>

DataSource ds2 = null;

InitialContext ctx2=new InitialContext();

ds2=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");

Connection conn2 = ds2.getConnection();

%>

Statement stmt2=conn2.createStatement();

String sql_gun2="select * from sm_t_salesheet" ;

ResultSet rs_gun2=stmt2.executeQuery(sql_gun2);

while(rs_gun2.next())

{

%>

}

rs_gun2.close();

stmt2.close();

%>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。