How to Handle Database Connection Error Using Java code?
<p>I am connecting to a DB2 server using the following code:</p>

<pre><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();
}
</code></pre>

<p>If the connection is not established, what is the best way to handle this situation?</p>
