高分求助:谁用过poolman??~~~~~见者有分~~~~~谢谢! 关于连接池的应该很多,你可以查下这里的FAQ试一试! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 poolman的主页说它已经不再支持了,而且我用过有很多bug,用Apache的连接池,挺好用的。我写了一个测试用的调用类,你可以参考一下。==============================================================================需要的jar包都在apache的common下:commons-dbcp-1.1.jarcommons-pool-1.1.jarcommons-collections.jar===============================================================================import org.apache.commons.dbcp.BasicDataSource;import java.sql.Connection;import java.sql.SQLException;import java.sql.*;public class ConnectionPool { private static BasicDataSource bds = new BasicDataSource(); private final static String url = "jdbc:oracle:thin:@192.168.1.251:1521:test"; private final static String user = "test"; private final static String password = "test"; private final static String driver = "oracle.jdbc.driver.OracleDriver"; static{ bds.setUrl(url); bds.setUsername(user); bds.setPassword(password); bds.setDriverClassName(driver); bds.setMaxActive(5); bds.setMaxIdle(5); bds.setMinIdle(2); } private ConnectionPool() { } public static Connection getConnection() throws SQLException { long btime = System.currentTimeMillis(); Connection conn = bds.getConnection(); System.out.println("Connection type: " + conn.getClass().getName()); System.out.println("Connection address: "+conn); long tt = System.currentTimeMillis() - btime; System.out.println("get Connection consume time is "+tt + " ms! connection address:"+conn); return conn; } public static void main(String[] args) { Connection conn = null; try { conn = ConnectionPool.getConnection(); conn.close(); conn = ConnectionPool.getConnection(); String sql = "select * from userpassport"; Statement stem = conn.createStatement(); ResultSet rs = stem.executeQuery(sql); while(rs.next()) { System.out.println(rs.getString("name")); } } catch (SQLException e) { e.printStackTrace(); } finally{ try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }} 高分求助:谁用过poolman??~~~~~见者有分~~~~~谢谢!呵呵~我看见了,?!?!?! 现面是一个在weblogic下的连接池应用的测试页面。如果你配置好了话,可以试一试!<%@page contentType="text/html;CHARSET=GBK" %><%@page import="java.sql.*,java.util.*,javax.naming.*,javax.sql.*" %><HTML><HEAD><TITLE>data connection</TITLE></HEAD><BODY><% Context ctx = null; Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL, "t3://localhost:80"); System.out.println("ok1"); try { ctx = new InitialContext(ht); System.out.println("ok2"); javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("你的JNDI Name"); System.out.println("ok3"); java.sql.Connection conn = ds.getConnection(); // You can now use the conn object to create Statements and retrieve result sets: Statement stmt = conn.createStatement(); ResultSet rs =stmt.executeQuery("select * from dual "); out.println("²éѯ½á¹û:<br>"); while (rs.next()) { out.println(rs.getString(1)+"<br>"); } // Close the statement and connection objects when you are finished: stmt.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { ctx.close(); } catch (Exception e) { // a failure occurred e.printStackTrace(); } } %> </BODY></HTML> Apache也是单个的连接池程序???还是像tomcat weblogic一样的服务器??? to kitty009(刁蛮公主):Tomcat的连接池用的就是Apache的。因为Tomcat就是Apache的子项目:->Apache的连接池是他的一个公共项目,就是commons下的一个包,只是还用到了commons下的其他两个包。 PoolMan在多线程争用时可能会出现线程死锁的问题!!!楼主可以看一下近几个月的程序员杂志具体哪一期忘了^)^ JAVA定义问题 Java写的Console程序,运行一段时间以后自动暂停。什么原因呢? java " . "的作用 请教一下Method.invoke方法 我想问一下,为什么向上转型会成功?而向下转型不成功.请各位说一下其中的原理,谢谢了. 请教 red hat下大家编辑 代码的时候一般用什么工具? java程序将dos文本与unix文本互转 新手请教用UltraEdit来运行java程序 如何向主窗口传递消息 抽象类中松造方法为什么不能是抽象的,没有方法体,不同样可以继承吗? 请问在Java Applet中如何发e-mail ?
我写了一个测试用的调用类,你可以参考一下。
==============================================================================
需要的jar包都在apache的common下:
commons-dbcp-1.1.jar
commons-pool-1.1.jar
commons-collections.jar===============================================================================
import org.apache.commons.dbcp.BasicDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.*;public class ConnectionPool { private static BasicDataSource bds = new BasicDataSource(); private final static String url = "jdbc:oracle:thin:@192.168.1.251:1521:test";
private final static String user = "test";
private final static String password = "test";
private final static String driver = "oracle.jdbc.driver.OracleDriver";
static{
bds.setUrl(url);
bds.setUsername(user);
bds.setPassword(password);
bds.setDriverClassName(driver);
bds.setMaxActive(5);
bds.setMaxIdle(5);
bds.setMinIdle(2);
} private ConnectionPool() {
} public static Connection getConnection()
throws SQLException
{
long btime = System.currentTimeMillis();
Connection conn = bds.getConnection();
System.out.println("Connection type: " + conn.getClass().getName());
System.out.println("Connection address: "+conn);
long tt = System.currentTimeMillis() - btime;
System.out.println("get Connection consume time is "+tt
+ " ms! connection address:"+conn);
return conn; } public static void main(String[] args) {
Connection conn = null;
try {
conn = ConnectionPool.getConnection();
conn.close();
conn = ConnectionPool.getConnection();
String sql = "select * from userpassport";
Statement stem = conn.createStatement();
ResultSet rs = stem.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getString("name"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
finally{
try {
conn.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
}}
呵呵~我看见了,?!?!?!
如果你配置好了话,可以试一试!<%@page contentType="text/html;CHARSET=GBK" %>
<%@page import="java.sql.*,java.util.*,javax.naming.*,javax.sql.*" %><HTML>
<HEAD>
<TITLE>
data connection</TITLE>
</HEAD>
<BODY><%
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:80"); System.out.println("ok1");
try {
ctx = new InitialContext(ht);
System.out.println("ok2");
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("你的JNDI Name");
System.out.println("ok3");
java.sql.Connection conn = ds.getConnection();
// You can now use the conn object to create Statements and retrieve result sets:
Statement stmt = conn.createStatement();
ResultSet rs =stmt.executeQuery("select * from dual ");
out.println("²éѯ½á¹û:<br>");
while (rs.next())
{
out.println(rs.getString(1)+"<br>");
}
// Close the statement and connection objects when you are finished:
stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
ctx.close();
}
catch (Exception e)
{ // a failure occurred
e.printStackTrace();
}
}
%>
</BODY>
</HTML>
还是像tomcat weblogic一样的服务器???
Tomcat的连接池用的就是Apache的。因为Tomcat就是Apache的子项目:->
Apache的连接池是他的一个公共项目,就是commons下的一个包,只是还用到了commons下的其他两个包。