Contents Index Loading and registering the JDBC driver UltraLite JDBC URLs pdf/preface.pdf

UltraLite User's Guide
  Developing UltraLite Java Applications
    Connecting to and configuring your UltraLite database

Connecting to the database using JDBC


Once the driver is declared, you can connect to the database using the standard JDBC DriverManager.getConnection method.

getConnection prototypes 

The JDBC DriverManager.getConnection method has several prototypes. These take the following arguments:

DriverManager.getConnection( String url, Properties info )
DriverManager.getConnection( String url )

The UltraLite driver supports each of these prototypes. The arguments are discussed in the following sections.

Driver Manager 

The DriverManager class maintains a list of the Driver classes that are currently loaded. It asks each driver in the list if it is capable of connecting to the URL. Once such a driver is found, the DriverManager attempts to use it to connect to the database.

Error handling 

To handle the case where a connection cannot be made, catch the SQLException as follows:

try{
   Class.forName(
      "ianywhere.ultralite.jdbc.JdbcDriver");
   Connection conn = DriverManager.getConnection(
      "jdbc:ultralite:asademo" );
   } catch(SQLException e){
   System.out.println( "Exception: " + e.getMessage() );
   e.printStackTrace();
   }

Contents Index Loading and registering the JDBC driver UltraLite JDBC URLs pdf/preface.pdf