Note that there are some explanatory texts on larger screens.

plurals
  1. POSerialize an Object Array to sent over Sockets
    text
    copied!<p>I have an array that I have created from a database ResultSet. I am trying to Serialize it so that I can send it over a socket stream. At the moment I am getting an error telling me that the array is not Serializable. The code I have is down below, the first part is the class to create an object for the array:</p> <pre><code>class ProteinData { private int ProteinKey; public ProteinData(Integer ProteinKey) { this.ProteinKey = ProteinKey; } public Integer getProteinKey() { return this.ProteinKey; } public void setProteinKey(Integer ProteinKey) { this.ProteinKey = ProteinKey; } } </code></pre> <p>The code to populate the array:</p> <pre><code>public List&lt;ProteinData&gt; readJavaObject(String query, Connection con) throws Exception { PreparedStatement stmt = con.prepareStatement(query); query_results = stmt.executeQuery(); while (query_results.next()) { ProteinData pro = new ProteinData(); pro.setProteinKey(query_results.getInt("ProteinKey")); tableData.add(pro); } query_results.close(); stmt.close(); return tableData; } </code></pre> <p>And the code to call this is:</p> <pre><code>List dataList = (List) this.readJavaObject(query, con); ObjectOutputStream output_stream = new ObjectOutputStream(socket.getOutputStream()); output_stream.writeObject(dataList); </code></pre> <p>And the code recieving this is:</p> <pre><code>List dataList = (List) input_stream.readObject(); </code></pre> <p>Can someone help me serailize this array. All I can find in forums is simple arrays(EG. int[]).</p> <p>I tried to add the serializable to the class and the UID number but got <code>java.lang.ClassNotFoundException: socketserver.ProteinData</code> error message. Does anyone now why?</p> <p>Thanks for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload