// JDBC RMI -- sample call to the JDBC through RMI import java.sql.*; import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class JRImpl extends UnicastRemoteObject implements JR { private JRConnection jrc [] = new JRConnection [5]; /** Default constructor */ public JRImpl () throws RemoteException { } /** Method to open a database connection */ public synchronized int openDatabase() throws RemoteException, SQLException, ClassNotFoundException { int connectionId; // Loop through connection table until an empty slot is found for (connectionId = 0; connectionId < jrc.length; connectionId++) { if (jrc [connectionId] == null) break; } // If no empty slots found, generate an error if (connectionId >= jrc.length) { System.out.println("Out of connection objects."); return -1; } // Create a connection for the new process and run it jrc [connectionId] = new JRConnection(); // Call the new connection's method to open a database connection jrc[connectionId].openDatabase(); // return the connection identifier return connectionId; } /** Issue a SQL query with a WHERE clause */ public void performSearch(int id, String searchString) throws RemoteException, SQLException { jrc[id].performSearch(searchString); } /** Fetch the next row from the current query result */ public String getNextRow(int id) throws RemoteException, SQLException { return jrc[id].getNextRow(); } /** Close the database connection */ public void closeDatabase(int id) throws RemoteException, SQLException { jrc[id].closeDatabase(); jrc[id] = null; } }