Configuring jConnect for J2EE servers

You can use the com.sybase.jdbc4.jdbc.SybConnectionPoolDataSource class to configure connection pools to an Adaptive Server server in application servers such as EAServer. The com.sybase.jdbc4.jdbc.SybConnectionPoolDataSource implementation of the javax.sql.ConnectionPoolDataSource interface provides getter and setter methods for every connection property.

You can also configure jConnect programmatically, for example:

private DataSource getDataSource ()
{
   SybConnectionPoolDataSource connectionPoolDataSource = new
      SybConnectionPoolDataSource();
   connectionPoolDataSource.setDatabaseName("pubs2");
   connectionPoolDataSource.setNetworkProtocol("Tds");
   connectionPoolDataSource.setServerName("localhost");
   connectionPoolDataSource.setPortNumber(5000);
   connectionPoolDataSource.setUser("sa");
   connectionPoolDataSource.setPassword(PASSWORD);
   return connectionPoolDataSource;
}
private void work () throws SQLException
{
   Connection conn = null;
   Statement stmt = null;
   DataSource ds = getDataSource();
   try {
      conn = ds.getConnection();
      stmt = conn.createStatement();
      // ...
   } 
   finally {
      if (stmt != null) {
         try { stmt.close(); } catch (Exception ex) { /* ignore */ }
      }
      if (conn != null) {
         try { conn.close(); } catch (Exception ex) { /* ignore */ }
      }
   }
}