JDBC question

Discussion in 'Java' started by shaji, Dec 21, 2005.

  1. shaji

    shaji Guest

    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?
     
    shaji, Dec 21, 2005
    #1
    1. Advertising

  2. shaji

    Viator Guest

    Why do you see a problem in that??
     
    Viator, Dec 21, 2005
    #2
    1. Advertising

  3. shaji

    Roedy Green Guest

    On 20 Dec 2005 23:17:51 -0800, "shaji" <> 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.
     
    Roedy Green, Dec 21, 2005
    #3
  4. shaji

    linc Guest

    Roedy Green wrote:
    > On 20 Dec 2005 23:17:51 -0800, "shaji" <> 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
     
    linc, Dec 21, 2005
    #4
  5. shaji

    Tim Terry Guest

    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
     
    Tim Terry, Dec 22, 2005
    #5
  6. shaji

    Rob Mitchell Guest

    "shaji" <> 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, Dec 23, 2005
    #6
  7. shaji

    Rob Mitchell Guest

    [posted and mailed]

    "shaji" <> 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, Dec 23, 2005
    #7
  8. shaji

    Guest

    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?
     
    , Dec 23, 2005
    #8
  9. shaji

    Rob Mitchell Guest

    [posted and mailed]

    "shaji" <> 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
     
    Rob Mitchell, Jan 27, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    769
    Keith Wansbrough
    Aug 16, 2004
  2. Betty
    Replies:
    1
    Views:
    9,889
    Juha Laiho
    May 21, 2005
  3. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,283
    robert
    Feb 11, 2006
  4. Bruce
    Replies:
    4
    Views:
    767
    Bjorn Abelli
    Mar 25, 2006
  5. Lew
    Replies:
    0
    Views:
    526
Loading...

Share This Page