• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pass ResultSet object from servlet to Java Client

 
Fabio Piergentili
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to pass a ResultSet to a java client. I have tried the following ( rs is a ResultSet from a DB wuery )

response.setContentType( "application/octet-stream" );
ObjectOutputStream oos =
new ObjectOutputStream( response.getOutputStream( ) );
oos.writeObject( rs);
oos.close();

I get an exception

javax.servlet.ServletException: com.mysql.jdbc.JDBC4ResultSet

com.mysql.jdbc4ResultSet is my rs object.

Anyone have any ideas?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fabio Piergentili wrote:I want to pass a ResultSet to a java client.

No, you don't.

What you want to do is to limit result sets to the very lowest levels of your application and to close them as soon as possible. They should never get passed anywhere near the UI or client.

Rather, read the data from the result set, store it in normal Java collections and/or beans, close the result set, and pass the data to the upper layers.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This reminds me of Bear's article about the power of the Map
 
Fabio Piergentili
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for setting me straight!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your welcome. And welcome to the the Ranch.

You'll find that what's we do here. Rather than give you a pat answer, you'll get advice about the best practices and how to do things right -- not merely get them to work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic