Connection retry attempts to HDR secondary servers
You can write applications so that if a connection is lost during query operations, HCL Informix® JDBC Driver returns a new connection to the secondary database server and the application reruns the queries.
The following example shows how to retry a connection
with the secondary server information, and then rerun an SQL statement
that received an error because the primary server connection failed:
public class HDRConnect {
static IfmxConnection conn;
public static void main(String[] args)
{
getConnection(args[0]);
doQuery( conn );
closeConnection();
}
static void getConnection( String url )
{
..
Class.forName("com.informix.jdbc.IfxDriver");
conn = (IfmxConnection )DriverManager.getConnection(url);
}
static void closeConnection()
{
try
{
conn.close();
}
catch (SQLException e)
{
System.out.println("ERROR: failed to close the connection!");
return;
}
}
static void doQuery( Connection con )
{
int rc=0;
String cmd=null;
Statement stmt = null;
try
{
// execute some sql statement
}
catch (SQLException e)
{
if (e.getErrorCode() == -79716 ) || (e.getErrorCode() == -79735)
// system or internal error
{
// This is expected behavior when primary server is down
getConnection(url);
doQuery(conn);
}
else
System.out.println("ERROR: execution failed - statement: " + cmd);
return;
}
}