I am connecting to a DB2 server using the following code:
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
try {
con = DriverManager.getConnection("jdbc:db2://IP:port/db name", "username", "password");
} catch (SQLException sqle) {
sqle.printStackTrace();
}
If the connection is not established, what is the best way to handle this situation?
If you’re asking whether you should try to re-connect or not – you most probably don’t want to implement that logic yourself, take some connection pooling library like C3P0 or DBCP.