import java.sql.*;
import java.rmi.*;

import RmiJdbc.*;
import java.net.InetAddress;

/**
 * This is a sample program for RmiJdbc client/server jdbc Driver
 * RmiJdbc relies on Java RMI for jdbc objects distribution
 */
public class TestClient {

  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();

      // Test with InstantDB java database engine
      // See http://www.lutris.com/products/instantDB/index.html
      // for info & download
      String url = "jdbc:idb:sample.prp";

      // RMI host will point to local host
      String rmiHost = new String(
       "//" + InetAddress.getLocalHost().getHostName());

      // RmiJdbc URL is of the form:
      // jdbc:rmi://<rmiHostName[:port]>/<jdbc-url>

      java.sql.Connection c = DriverManager.getConnection("jdbc:rmi:"
       + rmiHost + "/" + url);

      java.sql.Statement st = c.createStatement();
      java.sql.ResultSet rs = st.executeQuery("SELECT * FROM import1");

      java.sql.ResultSetMetaData md = rs.getMetaData();
      while(rs.next()) {
        System.out.print("\nTUPLE: | ");
        for(int i=1; i<= md.getColumnCount(); i++) {
          System.out.print(rs.getString(i) + " | ");
        }
      }

      rs.close();

    } catch(Exception e) {
      e.printStackTrace();
    }
  }
};