tomcat5.5中c3p0配置(JNDI,、hibernate配置)
http://www./topic/191545 c3p0 配置文件c3p0.properties
1>\Tomcat 5.5\conf\server.xml 2>\Tomcat 5.5\conf\context.xml 3>項(xiàng)目中\(zhòng)WebRoot\WEB-INF\web.xml 配置的代碼 1> 在tomcat\conf\server.xml的GlobalNamingResources中增加: 2> 在tomcat\conf\context.xml的Context中增加: <ResourceLink name="jdbc/mysqlDB" global="jdbc/mysqlDB" type="javax.sql.DataSource"/> 3> 在web.xml中增加: <resource-ref> (3)jsp測(cè)試頁(yè)面 <%@page language="java" import="java.util.*,java.sql.*,javax.naming.*,javax.sql.*" pageEncoding="GB2312"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head> <title>My JSP 'mysqlTest.jsp' starting page</title> </head> <body> Mysql數(shù)據(jù)庫(kù)測(cè)試<br><br><br> <% Connection conn=null; try { InitialContext ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mysqlDB"); conn=ds.getConnection(); } catch(NamingException ex) { ex.printStackTrace(); } String sql="select * from user"; PreparedStatement ps=conn.prepareStatement(sql); ResultSet rs=ps.executeQuery(); while(rs.next()) { %> 字段1:<%=rs.getString(1)%> 字段2:<%=rs.getString(2)%><br> <% } if(rs!=null) { rs.close(); rs=null; } if(ps!=null) { ps.close(); ps=null; } if(conn!=null) { conn.close(); conn=null; } %> </body> </html> http://wenku.baidu.com/view/b76a5bd97f1922791688e877.html 全局與單獨(dú)web配置 |
|