精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-10-14
最后修改:2009-10-14
Proxool连接池是sourceforge下的一个开源项目,这个项目提供一个健壮、易用的连接池,最为关键的是 <?xml version="1.0" encoding="UTF-8"?> <!-- the proxool configuration can be embedded within your own application's. Anything outside the "proxool" tag is ignored. --> <something-else-entirely> <proxool> <alias>mydata</alias> <driver-url> jdbc:mysql://localhost:3306/test </driver-url> <driver-class> org.gjt.mm.mysql.Driver </driver-class> <driver-properties> <property name="user" value="root" /> <property name="password" value="root" /> </driver-properties> <maximum-connection-count>10</maximum-connection-count> <house-keeping-test-sql> select CURRENT_DATE </house-keeping-test-sql> </proxool> </something-else-entirely> <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>ServletConfigurator</servlet-name> <servlet-class> org.logicalcobwebs.proxool.configuration.ServletConfigurator </servlet-class> <init-param> <param-name>xmlFile</param-name> <param-value>WEB-INF/proxool.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>Admin</servlet-name> <servlet-class> org.logicalcobwebs.proxool.admin.servlet.AdminServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>Admin</servlet-name> <url-pattern>/Admin</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
<%@ page import="java.sql.*"%> <%@ page contentType="text/html;charset=GB2312"%> <html> <head> <title>proxool测试</title> </head> <body> <h2> 使用 Proxool Connection Pool,用xml文件配置 </h2> <% Connection conn = null; Statement stmt = null; ResultSet rs = null; try { Class.forName("org.logicalcobwebs.proxool.ProxoolDriver"); conn = DriverManager.getConnection("proxool.mydata"); stmt = conn.createStatement(); out.println("<br />数据库连接成功<br /><br />"); String query = "select now()"; rs = stmt.executeQuery(query); while (rs.next()) { out.print(rs.getString(1) + "--OK<br />"); } stmt.close(); conn.close(); } catch (SQLException sqle) { out.println("sqle=" + sqle); out.println("<br />数据库连接失败<br /><br />"); } finally { if(stmt != null){ try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn != null){ try { conn.close(); out.println("<br />数据库关闭成功<br />"); } catch (SQLException e) { e.printStackTrace(); out.println("数据库关闭失败<br />"); } } } %> </body> </html>
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 2817 次