JDBC question

S

shaji

hi,

Is it a good practice to pass java.sql.ResultSet as a parameter?

method A(){
//creating db conn and getting resultset.
.......
ResultSet rs = stmt.executeQuery(query);
List myObjects = B(rs);
.......
}


method B(ResultSet rs){
//do processing with rs.
return myObjects;
}


Is this a good practice?
 
L

linc

Roedy said:
Why wouldn't it be?
Just be sure that by the time you get to your evaluation of rs, there's
no way rs.close has already happened.

I did that to myself last week.

Linc
 
T

Tim Terry

shaji said:
hi,

Is it a good practice to pass java.sql.ResultSet as a parameter?

method A(){
//creating db conn and getting resultset.
......
ResultSet rs = stmt.executeQuery(query);
List myObjects = B(rs);
......
}


method B(ResultSet rs){
//do processing with rs.
return myObjects;
}


Is this a good practice?

i would only like to reference an instance of a resultset in my data
layer. as long as this is the case its fine.

Tim
 
R

Rob Mitchell

hi,

Is it a good practice to pass java.sql.ResultSet as a parameter?

method A(){
//creating db conn and getting resultset.
......
ResultSet rs = stmt.executeQuery(query);
List myObjects = B(rs);
......
}


method B(ResultSet rs){
//do processing with rs.
return myObjects;
}


Is this a good practice?

Just make sure you call rs.close(); as well as the DataSource Connection
object.

Rob
 
R

Rob Mitchell

[posted and mailed]

hi,

Is it a good practice to pass java.sql.ResultSet as a parameter?

method A(){
//creating db conn and getting resultset.
......
ResultSet rs = stmt.executeQuery(query);
List myObjects = B(rs);
......
}


method B(ResultSet rs){
//do processing with rs.
return myObjects;
}


Is this a good practice?

Just make sure you call rs.close(); as well as the DataSource Connection
object.

Rob
 
R

richardsosborn

you have to watch how far you pass this around. while it's "open"
(referenced and not closed) this connection to the database is left
open. it's bound to it. do not place this in session or pass up to
the presentation layer. bad idea.
 
R

Rob Mitchell

[posted and mailed]

hi,

Is it a good practice to pass java.sql.ResultSet as a parameter?

method A(){
//creating db conn and getting resultset.
......
ResultSet rs = stmt.executeQuery(query);
List myObjects = B(rs);
......
}


method B(ResultSet rs){
//do processing with rs.
return myObjects;
}


Is this a good practice?

Sure, as long as your method B() is quick and either handles exceptions
and throws to caller and someone calls rs.close(); sometime. You don't
want to keep DataSource connection opened for a long time in web-based
applications since they're typically a shared resource.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top