/* -- ' Copyright by Erica Andrews aka CyLiKoN JeZuZ aka Li'L CJ, ' Febuary 2000. No one is permitted to implement this code ' or any portion of it on their site without the express written consent ' of the author (cylikon@hotmail.com - ./IcedPinky/). ' All rights reserved. ' This is the implementation for an RMI application I created to query ' my MySQL database and list all available rows in the db. This application uses ' a JDBC-compatible driver and VECTORS for processing the ResultSet, since RMI ' will throw a ResultSetNotSerializableException if you attempt to process a ' a result set the usual way. All info in the resultset is stored in a big Vector ' which is returned to the client. ' This class was hand-coded in Java by Erica Andrews on Feb. 1, 2000 ' The implementation uses the ' gweMySQLJDBC 0.9.2 driver and MySQL 3.22.9 for database connectivity. -- */ /* Feb 1, 1999 */ import java.io.*; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; import java.sql.*; import java.util.Vector; public class RMIMySQLIMPL extends UnicastRemoteObject implements RMIMySQL { // ---- creating Vector objects to store the information from each column in the database // ---- this is necessary since a ResultSet can't be iterated through normally using // ---- RMI - RMI will throw some kinda ResultSetNotSerializable exception if normal // ---- iteration of a ResultSet is attempted. public Vector resultsetV = new Vector(); // big vector which will hold the whole resultset public RMIMySQLIMPL() throws java.rmi.RemoteException { } //----------------- the actual MySQL/JDBC Method to be returned through RMI public Vector RMIResultSet() throws ClassNotFoundException,SQLException { Class.forName ("gwe.sql.gweMysqlDriver"); // --loading the JDBC driver Connection conn = DriverManager.getConnection ("jdbc:mysql://:3306/siteindex2","mySecretUserName","MySecretPassword"); Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery ("SELECT * FROM thesites"); while (rset.next()) { String id = rset.getString(1).trim(); String itsgroup = rset.getString(2).trim(); String title = rset.getString(3).trim(); String url = rset.getString(4).trim(); String thedate = rset.getString(5).trim(); // ----------------- packaging the database columns into a big Vector during next() resultsetV.addElement(id); resultsetV.addElement(itsgroup); resultsetV.addElement(title); resultsetV.addElement(url); resultsetV.addElement(thedate); } // --- end of while statement rset.close(); stmt.close(); conn.close(); this.resultsetV = resultsetV; return resultsetV; } // end of // method /* This method below is responsible for cleaning out any old data from past queries. Otherwise, the size of the vector and the data in it will keep growing and growing. */ public void VectorCleanUp() { resultsetV.removeAllElements(); this.resultsetV = resultsetV; } // ------------ the main RMI Binding method ----------------- public static void main (String args []) { RMIMySQLIMPL rsi; try { // ----Creating the security manager ----- if( System.getSecurityManager() == null ) { System.setSecurityManager( new RMISecurityManager() ); } LocateRegistry.createRegistry(1472); rsi = new RMIMySQLIMPL(); Naming.rebind("rmi:///RMIMySQLIMPL",rsi); System.out.print("\n\n RMI Success!: Object RMIMySQLIMPL has been created and bound to the RMI registry"); } catch (Exception ex) { System.out.println("\n\n Problem in main method of RMIMySQLIMPL :"+ex); ex.printStackTrace(); } // ---end Try/Catch } // ---- end of main method } // -end of class RMIMySQLIMPL