java如何实现当遇上网络中断或异常时,程序自动重新连接数据库。
下面是我的程序,如何改成我的需求。Connection sqlCon = null;
public Connection getSqlConnection() {
try{
Class.forName(Sql2000Info.driver);
sqlCon = DriverManager.getConnection(Sql2000Info.url,Sql2000Info.username,Sql2000Info.password);
if(sqlCon != null){
System.out.println("Sql 2000 连接成功.....");
} }catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
return sqlCon;
}
下面是我的程序,如何改成我的需求。Connection sqlCon = null;
public Connection getSqlConnection() {
try{
Class.forName(Sql2000Info.driver);
sqlCon = DriverManager.getConnection(Sql2000Info.url,Sql2000Info.username,Sql2000Info.password);
if(sqlCon != null){
System.out.println("Sql 2000 连接成功.....");
} }catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
return sqlCon;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货