The Java Program: Show.java

  1 import java.sql.Statement;
  2 import java.sql.Connection;
  3 import java.sql.ResultSet;
  4 import java.sql.ResultSetMetaData;
  5 import java.sql.DriverManager;
  6 import java.sql.SQLException;
  7 
  8 public class Show {
  9 
 10    private static Connection connection;
 11    private final static String jdbc_url = "jdbc:idb:/export/home/faculty/stansif/idb/sample.prp";
 12    private final static String host = "maelstrom.cs.fit.edu";
 13    private final static String db_name = "genealogy";
 14    private final static String cp = ".:/export/home/faculty/stansif/idb/RmiJdbc.jar";
 15 
 16    public static void main (String[] args) {
 17       try {
 18          Class.forName("RmiJdbc.RJDriver");
 19          connection = DriverManager.getConnection("jdbc:rmi://" + host + "/" + jdbc_url);
 20          showAll();
 21          connection.close();
 22       } catch (ClassNotFoundException e) {
 23          System.out.println ("This program must be run with '-classpath "+cp+"'");
 24       } catch (SQLException e) {
 25          e.printStackTrace();
 26       }
 27    }
 28 
 29    static void showAll() {
 30       try {
 31          Statement statement = connection.createStatement();
 32          ResultSet rs = statement.executeQuery("SELECT * FROM "+db_name);
 33          ResultSetMetaData rsmd = rs.getMetaData();
 34          int numberOfColumns = rsmd.getColumnCount();
 35          while (rs.next()) {
 36             for (int i = 1; i <= numberOfColumns; i++) {
 37                System.out.print (rs.getString(i) + ";");
 38             }
 39             System.out.println();
 40          }     
 41          statement.close();
 42       } catch (SQLException e) {
 43          System.out.println("Show all failed");
 44       }
 45    }
 46 }