<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RMI, RESULTSET, JDBC</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2 FACE="Arial">Hi,</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">I am using JDBC and RMI. I am getting the following error when trying to pass a ResultSet object via RMI.</FONT>
<BR><FONT SIZE=2 FACE="Arial">---</FONT>
<BR><FONT SIZE=2 FACE="Arial">DataMan exception: error unmarshalling return; nested exception is: java.io.WriteAbortedException: writing aborted; java.io.NotSerializable exception: sun.jdbc.odbc.JdbcOdbcResultSet</FONT></P>
<P><FONT SIZE=2 FACE="Arial">---</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">How can I make java.sql.ResultSet Serializable (w/o effecting the data) ? Can I pass a ResultSet through a network? Is a cast to Object neccessary?</FONT></P>
<P><FONT SIZE=2 FACE="Arial">Thanks,</FONT>
<BR><FONT SIZE=2 FACE="Arial">Christian Velez</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">Related Code</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">RMI SERVER</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">package expandTag;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">import java.rmi.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.rmi.Naming;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.rmi.RemoteException;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.rmi.server.UnicastRemoteObject;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.net.SocketPermission;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">public class DataManServer {</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">public static void main(String [] args) throws Exception {</FONT>
<BR> <FONT SIZE=2 FACE="Arial">if (System.getSecurityManager() == null) {</FONT>
<BR> <FONT SIZE=2 FACE="Arial">System.setSecurityManager(new RMISecurityManager());</FONT>
<BR> <FONT SIZE=2 FACE="Arial">}</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">try {</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">DataManImpl dm = new DataManImpl();</FONT>
<BR> <FONT SIZE=2 FACE="Arial">System.out.print("Expand Tag Data Manager starting ...");</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">Naming.rebind(DataMan.LOOKUPNAME, dm);</FONT>
<BR> <FONT SIZE=2 FACE="Arial">System.out.print("ready.");</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> </FONT>
<BR> <FONT SIZE=2 FACE="Arial"> } catch (Exception e) {</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> System.err.println(e);</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> System.exit(1);</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> } </FONT>
<BR> <FONT SIZE=2 FACE="Arial">}</FONT>
<BR><FONT SIZE=2 FACE="Arial">}</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">Related Code</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">RMI INTERFACE</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">package expandTag;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">import java.util.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.rmi.*;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">public interface DataMan extends java.rmi.Remote { </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> // The object returned is a java.sql.ResultSet</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Object getETData(String dbname) throws RemoteException;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> public final static String LOOKUPNAME = </FONT>
<BR><FONT SIZE=2 FACE="Arial"> "rmi://198.80.58.19:1099/DataMan";</FONT>
<BR><FONT SIZE=2 FACE="Arial">}</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">Related Code</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">RMI IMPLEMENTAITON</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">package expandTag;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">import java.sql.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.rmi.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.rmi.server.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.sql.*;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">public class DataManImpl extends UnicastRemoteObject </FONT>
<BR><FONT SIZE=2 FACE="Arial"> implements DataMan {</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">public DataManImpl() throws RemoteException {</FONT>
<BR> <FONT SIZE=2 FACE="Arial">super();</FONT>
<BR> <FONT SIZE=2 FACE="Arial">} </FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> // The object returned is a java.sql.ResultSet</FONT>
<BR><FONT SIZE=2 FACE="Arial"> public Object getETData(String dbname) throws RemoteException {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> try {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Object spec;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> String dbURL = "jdbc:odbc:ETdatabase";</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Class c = Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Connection conn = </FONT>
<BR><FONT SIZE=2 FACE="Arial"> DriverManager.getConnection(dbURL, "dbo", "");</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> String query = "sp_getETData " + dbname;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> Statement stmt = conn.createStatement();</FONT>
<BR><FONT SIZE=2 FACE="Arial"> spec = (Object)stmt.executeQuery(query);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> return spec; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> } catch (ClassNotFoundException ex) {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> System.out.println("Driver Manager error");</FONT>
<BR><FONT SIZE=2 FACE="Arial"> } catch (SQLException ex) {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> System.out.println(ex);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT SIZE=2 FACE="Arial"> return null;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">}</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">Related Code</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">RMI CLIENT</FONT>
<BR><FONT SIZE=2 FACE="Arial">----------------------------</FONT>
<BR><FONT SIZE=2 FACE="Arial">package expandTag;</FONT>
<BR><FONT SIZE=2 FACE="Arial">/* Command Line : </FONT>
<BR><FONT SIZE=2 FACE="Arial"> java -Djava.security.policy={policy file} expandTag.ExpandTagDataStore {dbname}</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> The client requires:</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> DataMan.class</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> DataManImpl_Stub.class</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> The server requires:</FONT>
<BR><FONT SIZE=2 FACE="Arial"> DataManImpl_Skel.class</FONT>
<BR><FONT SIZE=2 FACE="Arial">*/</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">import java.rmi.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.sql.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.io.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.lang.*;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.io.IOException;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.io.PrintWriter;</FONT>
<BR><FONT SIZE=2 FACE="Arial">import java.io.FileWriter;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">public class ExpandTagDataStore {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> static protected DataMan dmConnection = null; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> static private boolean flushtext = true;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> static private String dir = "c:/"; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> static private PrintWriter ETFile; </FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">static private String dbname;</FONT>
<BR> <FONT SIZE=2 FACE="Arial">static private ResultSet spec;</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">public static void main(String args[]) {</FONT>
<BR> <FONT SIZE=2 FACE="Arial">//Required for network implementation</FONT>
<BR><FONT SIZE=2 FACE="Arial"> System.setSecurityManager(new RMISecurityManager());</FONT>
<BR>
<BR> <FONT SIZE=2 FACE="Arial">System.out.println("Starting ETTextApp...");</FONT>
<BR> <FONT SIZE=2 FACE="Arial">dbname = args[0]; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> try {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> dmConnection = (DataMan)Naming.lookup(DataMan.LOOKUPNAME);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> spec = (ResultSet)dmConnection.getETData(dbname);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> } catch (Exception e) {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> System.out.println("DataMan exception: " + e.getMessage());</FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> //writeXMLFile(ETSpec);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT SIZE=2 FACE="Arial">...</FONT>
<BR><FONT SIZE=2 FACE="Arial">}</FONT>
</P>
</BODY>
</HTML>