0
Statement st=(Statement) sqlcon.createStatement();
ResultSet p=st.executeQuery("SELECT * FROM `chat`.`online_users`");

I have got the data from the database through the object of ResultSet but when i am sending it to the client through sockets it is giving an error. It is not serializable. How to send data and receive data retrieved through ResultSet across socket?

Luv
  • 5,381
  • 9
  • 48
  • 61

3 Answers3

2

Read the data from the ResultSet, push it in a List then send your List. All the implementations like ArrayList already implement Serializable interface, you can read this answer to know more about List Serialization.

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
1

Well, you could inherit from ResultSet and implement Serializable interfaces in a new class. I would suggest a better approach would be to send XML between layers, or if you want an all Java solution, how about creating an object for each row, stuffing them in a collection class or vector, and serializing it instead of the ResultSet class.

Mads
  • 724
  • 3
  • 10
1

Since it needs to be serializable and send it across a network connection a CachedRowSet seems to be a good option for you to try.

ChadNC
  • 2,528
  • 4
  • 25
  • 39