67,550
社区成员




楼主连得 是不是 你们正式数据库
你这种情况我真的遇见过(是在前一家公司)
是就是这个事,情况就是这个情况 我也没有什么好说的
下面代码是我用的循环获得的数据库连接 我以前用这个是连接上的 不过最好不要用
还要从你们项目中着手 估计是什么地方连接没有关
public static synchronized Connection getConnection() {
boolean con = true;
long t1=System.currentTimeMillis();
long t2=0;
while (con) {
try {
//如果访问超过30分钟就自动放弃并终止
if (t2-t1>1800000) {
//设置发送信息
SendMail sm=new SendMail();
System.out.println("get connection fail!");
System.exit(-1);
}
con = false;
conn = DriverManager.getConnection("proxool.app");
} catch (SQLException e) {
// e.printStackTrace();
con = true;
t2=System.currentTimeMillis();
}
}
if (conn != null) {
} else {
System.out.println("connection fail!!!");
}
return conn;
}
public static synchronized void closeConn() {
if (conn != null) {
try {
// System.out.println("connection is closed");
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn = null;
}
}