/* Feb 1, 1999 */ /* ***************************************************************************** Copyright 2000 by Erica Andrews (cylikon@hotmail.com). All rights reserved. ./ButchWhipAppeal/ ./IcedPinky/ NO portion of this software may be used in ANY way by anyone other than myself without my express written consent. If it is downloaded for testing, it must be deleted from your system within 24 hours. Any other use constitutes piracy and fraudulent misuse of this software, punishable in a court of law. Copyright 2000 by Erica Andrews. All rights reserved. ***************************************************************************** */ import java.io.*; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; import java.sql.*; import sun.jdbc.rowset.*; import java.lang.SecurityManager; public class RMIMySQLIMPL2 extends UnicastRemoteObject implements RMIMySQL2 { // ---- In this example, the result set will be stored into a CachedRowSet, a little early // ---- release extension I found at the JDC. Unlike regular result sets, the CachedRowSet // ---- is serializable. Like the vector used in my other RMI example, the CachedRowSet // ---- acts as a collection mechanism, but this method is MUCH simpler. // ---- RMI - RMI will throw some kinda ResultSetNotSerializable exception if normal // ---- iteration of a ResultSet is attempted. public CachedRowSet crs; // CachedRowSet to hold the results public RMIMySQLIMPL2() throws java.rmi.RemoteException { } //----------------- the actual MySQL/JDBC Method to be returned through RMI public CachedRowSet RMIResultSet() throws ClassNotFoundException,SQLException { Class.forName ("gwe.sql.gweMysqlDriver"); // --loading the JDBC driver Connection conn = DriverManager.getConnection ("jdbc:mysql://:3306/siteindex2","OMITTED","OMITTED"); Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery ("SELECT * FROM thesites"); crs = new CachedRowSet(); // initialize the cached rowset crs.populate(rset); // store the ResultSet into the CachedRowSet rset.close(); stmt.close(); conn.close(); this.crs = crs; return crs; } // end of // method /* This method below is responsible for cleaning out any old data from past queries. This is to conserve system resources and to ensure that no old data lingers in new CachedRowSet collections.. */ public void ResultSetCleanUp() throws SQLException { crs.close(); // clean all rows out of the rowset for future use this.crs = crs; } // ------------ the main RMI Binding method ----------------- public static void main (String args []) { RMIMySQLIMPL2 rsi; try { // ----Creating the security manager ----- /* if( System.getSecurityManager() == null ) { System.setSecurityManager(new RMISecurityManager() ); } */ LocateRegistry.createRegistry(1473); rsi = new RMIMySQLIMPL2(); Naming.rebind("//whip1472:1473/CachedRowExample",rsi); System.out.print("\n\n RMI Success!: Object CachedRowExample 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 // now overriding the checkPackageAccess method of the Security Manager (currently commented out) /* public void checkPackageAccess(String pkg) { // check no package access } //end of method */ } // -end of class RMIMySQLIMPL