Relational Junction dBase 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 dBase driver .jars to some directory at a server machine, e.g.: c:/rmiserver
3. Suppose we have our DBF files at c:/rmiserver/dbffiles
4. Start the RMI server using the command

java -classpath "RmiJdbc.jar;dbfdriver.jar;log4j.jar" org.objectweb.rmijdbc.RJJdbcServer com.relationaljunction.jdbc.dbf.DBFDriver2

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 dBase .jar files are not required at the client side).

java -classpath “.;RmiJdbc.jar” RMIClient

public class RMIClient {
public static void main(String[] args) {
try {
// Register RmiJdbc Driver in jdbc DriverManager
// On some platforms with some java VMs, newInstance() is necessary...
Class.forName("org.objectweb.rmijdbc.Driver").newInstance();
// our JDBC url that will be used at the server machine.
// The property 'singletonConnection = true' is recommended.
String url = "jdbc:relationaljunction:dbf:dbffiles?singletonConnection=true";
// in this example an RMI host will point to local host
String rmiHost = "//" + java.net.InetAddress.getLocalHost().getHostName();
// RmiJdbc URL is of the form:
// jdbc:rmi://<rmiHostName[:port]>/
java.sql.Connection c = java.sql.DriverManager.getConnection("jdbc:rmi:" + rmiHost + "/" + url);
// these Connection, Statement and ResultSet objects are remote!
// All is occurring at the server side!
java.sql.Statement st = c.createStatement();
java.sql.ResultSet rs = st.executeQuery("SELECT prod.descr AS "Product", regs.regionname AS "Region", " +
"minprice, stdprice, FORMATDATETIME(startdate, 'dd " +
"MMMMM yyyy' ) AS "Start Date", FORMATDATETIME(enddate, 'dd MMMMM yyyy') " +
"AS "End Date" FROM "prices.dbf" ps JOIN "regions.dbf" regs ON " +
"ps.regionid = regs.id JOIN "products.dbf" prod ON prod.prodid = ps.prodid " +
"nORDER BY "Product"");
java.sql.ResultSetMetaData md = rs.getMetaData();
while (rs.next()) {
System.out.print("n");
for (int i = 1; i <= md.getColumnCount(); i++) {
System.out.print(rs.getString(i) + "t");
}
}
rs.close();
st.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}