Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   JDBC question (http://www.velocityreviews.com/forums/t148719-jdbc-question.html)

shaji 12-21-2005 07:17 AM

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?


Viator 12-21-2005 07:39 AM

Re: JDBC question
 
Why do you see a problem in that??


Roedy Green 12-21-2005 11:02 AM

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.

linc 12-21-2005 10:57 PM

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

Tim Terry 12-22-2005 12:21 AM

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

Rob Mitchell 12-23-2005 05:51 PM

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


Rob Mitchell 12-23-2005 05:51 PM

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


richardsosborn@gmail.com 12-23-2005 05:58 PM

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?



Rob Mitchell 01-27-2006 03:24 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57