resin连接池配置
resin的conf下有一个配置文件resin.conf,里面有一个接连池的例子,是连MySql的。我用的是SQL Server,所以就在例子上做了点改动,改动后内容如下:
<!--
- Sample database pool for SQL Server
- The JDBC name is java:comp/env/jdbc/sql
-->
<database>
<jndi-name>jdbc/sql</jndi-name>
<driver type="com.microsoft.jdbc.sqlserver.SQLServerDriver">
<url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test</url>
<user>sa</user>
<password></password>
</driver>
<prepared-statement-cache-size>8</prepared-statement-cache-size>
<max-connections>20</max-connections>
<max-idle-time>30s</max-idle-time>
</database>
然后建一个测试网页test.jsp
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
DataSource ds = null;
try{
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/sql");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
String strSql = " select * from test";
ResultSet rs = stmt.executeQuery(strSql);
while(rs.next()){
out.println(rs.getString(1)+"<br>");
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception ex){
ex.printStackTrace();
out.print(ex.getMessage());
}
%>
测试成功,相当顺利!
再配一个连接Oracle的连接池:
<!--
- Sample database pool for Oracle
-
- The JDBC name is java:comp/env/jdbc/ora
-->
<database>
<jndi-name>jdbc/ora</jndi-name>
<driver type="oracle.jdbc.driver.OracleDriver">
<url>jdbc:oracle:thin:@10.32.88.88:1521:ckkh</url>
<user>ckkh</user>
<password>ckkhdba</password>
</driver>
<prepared-statement-cache-size>8</prepared-statement-cache-size>
<max-connections>20</max-connections>
<max-idle-time>30s</max-idle-time>
</database>