Relational Junction MS Access JDBC Driver RMI

Using the driver as a client/server via RMI

You can use the driver as a client/server (JDBC type 3) through the RMI (remote method invocation) technology. One of possible solutions to implement that is using a RMI-JDBC bridge (http://rmijdbc.ow2.org/).

Advantages of using an RMI server:

1) It is a platform-independent multithreading server. You can run it on any OS supporting Java.
2) It can be used as an alternative to FTP (SFTP, HTTP, etc) protocols for accessing remote files. Besides an RMI server has performance higher than mentioned protocols, because it does not require synchronizing files between the driver cache and a remote FTP (SFTP, HTTP, etc) server, especially while updating data.
3) The driver .jar files are stored only at a server. So if you want to update the driver, you just need to update the driver at the server, but not for each client computer.
4) It supports the secure channel via SSL and RMI Security Manager.

Starting server:

1. Download the RmiJdbc project files at http://rmijdbc.ow2.org/download.html
2. Copy RmiJdbc.jar and the StelsMDB driver .jars to some directory at a server machine, e.g.: c:/rmiserver
3. Suppose we have our MDB files at c:/rmiserver/mdbfiles
4. Start the RMI server using the command

java -classpath “RmiJdbc.jar;mdbdriver.jar;log4j.jar;commons_lang.jar;commons_logging.jar” org.objectweb.rmijdbc.RJJdbcServer com.relationaljunction.jdbc.mdb.MDBDriver2

5. After executing the command the RMI server starts, listens 1099 port by default and registers the driver class. SSL and RMI security manager by default are not used. For more details about command-line parameters supported by an RMI server see http://rmijdbc.ow2.org/documentation.html

Starting client:

1. Copy RmiJdbc.jar to your client machine as well.
2. Compile the example below
3. Run the example (note that StelsMDB .jar files are not required at the client side).

java -classpath “.;RmiJdbc.jar” RMIClient


1.public class RMIClient { 
2.  public static void main(String[] args) {
3.    try {
4.     // Register RmiJdbc Driver in jdbc DriverManager
5.    // On some platforms with some java VMs, newInstance() is necessary...
6.     Class.forName("org.objectweb.rmijdbc.Driver").newInstance();
7. 
8.     // our JDBC url that will be used at the server machine.
9.     // The property 'singletonConnection = true' is recommended.
10.     String url = "jdbc:relationaljunction:mdb:mdbfiles/testdb.mdb?singletonConnection=true";
11.     
12.        // in this example an RMI host will point to local host
13.     String rmiHost = "//" + java.net.InetAddress.getLocalHost().getHostName();
14.
15.     // RmiJdbc URL is of the form:
16.     // jdbc:rmi://<rmiHostName[:port]>/
17.   java.sql.Connection c = java.sql.DriverManager.getConnection("jdbc:rmi:" + rmiHost + "/"   +url);
18.  // these Connection, Statement and ResultSet objects are remote!
19.     // All is occurring at the server side!
20.     java.sql.Statement st = c.createStatement();
21.     java.sql.ResultSet rs = st.executeQuery("SELECT prod.description AS "Product", regs.regionname AS "Region", " +
22.    "minprice, stdprice, FORMATDATETIME(startdate, 'dd " +
23.    "MMMMM yyyy' ) AS "Start Date", FORMATDATETIME(enddate, 'dd MMMMM yyyy') " +
24.    "AS "End Date" FROM prices ps JOIN regions regs ON " +
25.    "ps.regionid = regs.id JOIN products prod ON prod.prodid = ps.prodid " +
26.    "nORDER BY "Product"");
27.       java.sql.ResultSetMetaData md = rs.getMetaData();
28.     while (rs.next()) {
29.      System.out.print("n");
30.      for (int i = 1; i <= md.getColumnCount(); i++) {
31.        System.out.print(rs.getString(i) + "t");
32.      }
33.     }
34.      rs.close();
35.    st.close();
36.    c.close();
37.   } catch (Exception e) {
38.     e.printStackTrace();
39.   }
40.  }
41. }