日期:2014-05-20  浏览次数:20772 次

C3P0运行几天后报错,并挂掉 请高手指点指点
C3P0运行几天后报错,并挂掉
报了这样的错误:

WARN [com.mchange.v2.resourcepool.BasicResourcePool] - <com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e8f8c5 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: >
java.sql.SQLException: Io 异常: Connection reset

请问这是什么原因呢?

------解决方案--------------------
import java.sql.Connection;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class C3p0Util {
static String driver_2005="com.microsoft.sqlserver.jdbc.SQLServerDriver";
static String url_2005="jdbc:sqlserver://localhost:1433;databasename=pubs";

static String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
static String url = "jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs";
static String user = "sa";
static String password = null;

static ComboPooledDataSource cpds = null;

static {
try {
cpds = new ComboPooledDataSource();
//driver 2000
//cpds.setDriverClass(driver);
//cpds.setJdbcUrl(url);
//driver2005
cpds.setDriverClass(driver_2005);
cpds.setJdbcUrl(url_2005);
cpds.setUser(user);
cpds.setPassword(password);
} catch (Exception e) {
e.printStackTrace();
}
}

//获取连接
public static Connection getConnection() {
Connection conn = null;
try {
conn = cpds.getConnection();
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}

public static void main(String[] args) {
Connection conn = C3p0Util.getConnection();
System.out.println(conn);
}
}


c3p0.jar要
------解决方案--------------------
顶,写一个测试类调通后然后再使用,这样方便一点建议用main方法