java实现网络中断时自动重新连接数据库
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;
}