I'm t rying to connect to a SyBase database with the code below. I get three results with equal distribution:
1) It gets through and makes the connection - I'm golden
2) I get:
Exception: JZ006: Caught IOException: java.net.SocketException: Connection aborted by peer: socket write error
3) I get:
Exception: JZ0C0: Connection is already closed.
Anybody using SyBase with JDBC seen this before?
private Connection connectToSyBase( String username, String password, String ipAddress, int port )
throws SQLException
{
Connection con = null; // For return
String url = null;
try {
// Load and register the Sybase driver, if not already done
loadSyBaseDrivers();
// Establish a connection
// "jdbc:sybase" => identifies the driver
// "Tds" => the Sybase communication protocol for Adaptive Server
// "host:port/database" => the Adaptive Server hostname and listening port
url = "jdbc:sybase:Tds:" + ipAddress + ":" + port;
System.out.println( "ConnectionFactory.connectToSyBase: getConnection" );
con = DriverManager.getConnection( url, username, password );
System.out.println( "ConnectionFactory.connectToSyBase: success!" );
} catch( Exception e ) {
String msg = "Exception: " + e.getMessage();
System.out.println( "ConnectionFactory.connectToSyBase: " + msg );
throw new SQLException( msg );
}
// We're golden - return the Connection
return con;
}
/**
* Load SyBase drivers
*/
private void loadSyBaseDrivers()
throws SQLException
{
if( _sybDriver == null ) {
try {
System.out.println( "ConnectionFactory.loadSyBaseDrivers: load SybDriver" );
_sybDriver = (SybDriver)Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();
System.out.println( "ConnectionFactory.loadSyBaseDrivers: set VERSION" );
_sybDriver.setVersion( com.sybase.jdbcx.SybDriver.VERSION_5 );
System.out.println( "ConnectionFactory.loadSyBaseDrivers: registerDriver" );
DriverManager.registerDriver( _sybDriver );
} catch( InstantiationException ie ) {
// All exceptions get rethrown as SQLException
String msg = "InstantiationException: " + ie.getMessage();
System.out.println( "ConnectionFactory.loadSyBaseDrivers: " + msg );
throw new SQLException( msg );
} catch( ClassNotFoundException cnfe ) {
String msg = "ClassNotFoundException: " + cnfe.getMessage();
System.out.println( "ConnectionFactory.loadSyBaseDrivers: " + msg );
throw new SQLException( msg );
} catch( SQLException e ) {
String msg = "SQLException: " + e.getMessage();
System.out.println( "ConnConnectionFactory.loadSyBaseDriversectionFactory: " + msg );
throw new SQLException( msg );
} catch( Exception e ) {
String msg = "Exception: " + e.getMessage();
System.out.println( "ConnectionFactory.loadSyBaseDrivers: " + msg );
throw new SQLException( msg );
}
}
}