Mimer SQL Documentation TOC PREV NEXT INDEX

Mimer SQL Developer Site

http://developer.mimer.com


Connecting with the Mimer JDBC Driver


The connection provides the link between the application and the Mimer SQL database server. To make a connection using the DriverManager class requires two operations:

The class name of both versions of the Mimer JDBC Driver is:

 com.mimer.jdbc.Driver. 
 

The class name of the Mimer Jtrace Driver is:

 com.mimer.jtrace.Driver. 

The jar file referenced in the CLASSPATH determines which version of the driver is loaded.

Loading a Driver

To use the Mimer JDBC driver, it must be loaded into the Java environment. The Java environment locates a driver by a search along the class path, defined in the CLASSPATH environment variable.

The CLASSPATH environment variable informs the Java environment where to find Java class files, such as the Mimer JDBC drivers. The Mimer JDBC driver jar files, including the directory specification, should be added to the Java class path.

Loading a driver using the standard Class.forName method is very simple:

 import java.io.*;
 import java.sql.*;
 
 ...
 
 try {
         Class.forName("com.mimer.jdbc.Driver");
 
     } catch (java.lang.ClassNotFoundException cnf) {
         System.err.println("JDBC driver not found");
         return;
     }

Alternatively, the DriverManager, when it initializes, looks for a jdbc.drivers property in the system properties. The jdbc.drivers property is a colon-separated list of drivers.

The DriverManager attempts to load each of the named drivers in this list of drivers. The jdbc.drivers property can be set like any other Java property, by using the -D option:

 java -Djdbc.drivers=com.mimer.jdbc.Driver class
 

The property can also be set from within the Java application or applet:

 Properties prp = System.getProperties();
 prp.put("jdbc.drivers",
            "com.mimer.jdbc.Driver:com.mimer.jtrace.Driver");
 System.setProperties(prp);
 
Note: Neither of the mechanisms used to load the driver specify that the application will actually use the driver. The driver is merely loaded and registered with the DriverManager.

Making a Connection

To make the actual database connection, a URL string is passed to the DriverManager.getConnection method in the JDBC management layer.

The URL defines the data source to connect to. The JDBC management layer locates a registered driver that can connect to the database represented by the URL.

Supported URL Syntax

The Mimer JDBC Driver supports the following URL syntax:

 jdbc:mimer:[URL-field-list][property-list]
 

All fields in the URL-field-list are optional.

The database server host computer, with or without a user specification, is introduced by // and the database name is introduced by /, for example:

 [//[user[:password]@]serverName[:portNumber]] [/databaseName]
 

A Connection object is returned from the getConnection method, for example:

 String url = "jdbc:mimer://MIMER_ADM:admin@localhost/ExampleDB";
 Connection con = DriverManager.getConnection(url);
 

Alternatively, the getConnection method allows the user name and password to be passed as parameters:

 url = "jdbc:mimer://localhost/ExampleDB";
 con = DriverManager.getConnection(url, "MIMER_ADM", "admin");

Mimer JDBC Driver Property-list

The property-list for the Mimer JDBC Driver is optional. The list is introduced by a leading question mark ? and where there are several properties defined they are separated by ampersands &, for example:

    ?property=value[&property=value[&property=value]]
 

The following properties are supported:
Property
Explanation
 databaseName

Name of database server to access

 user

User name used to log in to the database

 password

Password used for the login

 serverName

Computer on which the database server is running, the default is localhost

 portNumber

Port number to use on the database server host, the default is 1360

Example Connection

The following demonstrates a connection using the driver properties:

 url = "jdbc:mimer:?databaseName=ExampleDB"
                + "&user=MIMER_ADM"
                + "&password=admin"
                + "&serverName=localhost";
 con = DriverManager.getConnection(url);
 

Alternatively a java.util.Properties object can be used:

 Properties dbProp = new Properties();
 
 dbProp.put("databaseName", "ExampleDB");
 dbProp.put("user", "MIMER_ADM");
 dbProp.put("password", "admin");
 con = DriverManager.getConnection("jdbc:mimer:", dbProp);
 

Elements from the URL-field-list and the property-list can be combined:

 url = "jdbc:mimer:/ExampleDB"
                + "?user=MIMER_ADM"
                + "&password=admin";
 

The DriverPropertyInfo class is available for programmers who need to interact with a driver to discover the properties that are required to make a connection. This enables a generic GUI tool to prompt the user for the Mimer SQL connection properties:

 Driver drv;
 DriverPropertyInfo [] drvInfo;
 
 drv = DriverManager.getDriver("jdbc:mimer:");
 drvInfo = drv.getPropertyInfo("jdbc:mimer:", null);
 for (int i = 0; i < drvInfo.length; i++) {
     System.out.println(drvInfo[i].name + ": " + drvInfo[i].value);
 }
 

After connecting to the database, all sorts of information about the driver and database is available through the use of the getMetadata method:

 DatabaseMetaData dbmd;
  
 dbmd = con.getMetaData();
        
 System.out.println("Driver      " + dbmd.getDriverName());
 System.out.println("    Version " + dbmd.getDriverVersion());
 System.out.println("Database    " + dbmd.getDatabaseProductName());
 System.out.println("    Version " + dbmd.getDatabaseProductVersion ());
 

The close method tells JDBC to disconnect from the Mimer SQL database server. JDBC resources are also released:

 con.close
 

It is usual for connections to be explicitly closed when no longer required. The normal Java garbage collection has no way of freeing external resources, such as the Mimer SQL database server.



Upright Database Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40
dbtechnology@upright.se
Mimer SQL Documentation TOC PREV NEXT INDEX