![]() |
JDBC question
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? |
Re: JDBC question
Why do you see a problem in that??
|
Re: JDBC question
On 20 Dec 2005 23:17:51 -0800, "shaji" <shaji.cc@gmail.com> wrote,
quoted or indirectly quoted someone who said : > > >Is this a good practice? Why wouldn't it be? -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. |
Re: JDBC question
Roedy Green wrote:
> On 20 Dec 2005 23:17:51 -0800, "shaji" <shaji.cc@gmail.com> wrote, > quoted or indirectly quoted someone who said : > > >> >>Is this a good practice? > > > 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 |
Re: JDBC question
shaji wrote:
> 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 |
Re: JDBC question
"shaji" <shaji.cc@gmail.com> wrote in news:1135149471.030002.63100
@g47g2000cwa.googlegroups.com: > 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 |
Re: JDBC question
[posted and mailed]
"shaji" <shaji.cc@gmail.com> wrote in news:1135149471.030002.63100 @g47g2000cwa.googlegroups.com: > 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 |
Re: JDBC question
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. shaji wrote: > 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? |
Re: JDBC question
[posted and mailed]
"shaji" <shaji.cc@gmail.com> wrote in news:1135149471.030002.63100 @g47g2000cwa.googlegroups.com: > 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 |
| All times are GMT. The time now is 11:44 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.