Invoking the jConnect driver

To register and invoke jConnect, add jConnect to the jdbc.drivers system property. At initialization, the DriverManager class attempts to load the drivers listed in jdbc.drivers. This is less efficient than calling Class.forName. You can list multiple drivers in this property, separated with a colon (:). The following code samples show how to add a driver to jdbc.drivers within a program:

Properties sysProps = System.getProperties();
String drivers = "com.sybase.jdbc4.jdbc.SybDriver";
String oldDrivers =
sysProps.getProperty("jdbc.drivers");
if (oldDrivers != null)
   drivers += ":" + oldDrivers;
 sysProps.put("jdbc.drivers", drivers.toString());

NoteSystem.getProperties is not allowed for Java applets. Use the Class.forName method instead.

In Java 6 and JDBC 4, the instantiation of JDBC drivers has been simplified. You can use the Java system property jdbc.drivers to specify driver classes, for example:

java -Djdbc.drivers=com.sybase.jdbc4.jdbc.SybDriver UseDriver

There is no need for the UseDriver program to load the driver explicitly:

public class UseDriver
{
   public static void main(String[] args)
   {
      try {
         Connection conn = java.sql.DriverManager.getConnection
            ("jdbc:sybase:Tds:localhost:5000?USER=sa&PASSWORD=secret");
         // more code to use connection ...
      }
      catch (SQLException se){
         System.out.println("ERROR: SQLException "+se);
      }
   }
}