简体   繁体   中英

How to receive data via sockets retrieved through Result Set?

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?

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.

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.

由于它需要可序列化并通过网络连接发送,因此CachedRowSet似乎是您尝试的不错选择。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM