Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.databases > #264

Re: Close resultset but n

From joeNOSPAM@BEA.com.remove-dii-this
Subject Re: Close resultset but n
Message-ID <90816268-847f-4656-9d2f-6ac3b2af1533@x35g2000hsb.googlegroups.com> (permalink)
Newsgroups comp.lang.java.databases
References <gbtr3j$lbj$1@ss408.t-com.hr>
Date 2011-04-27 15:22 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.databases
On Sep 30, 11:28 am, "polilop" <fmatosicREM...@inet.hr> wrote:
> I have a method that has a resultset as return value, so i can not close the
> connection:
>
> public ResultSet getSomething()
>  {
>
>   StringBuffer sql = new StringBuffer();
>   Statement stmt = null;
>
>   try {
>    con = SQLTestFactory.createConnection();
>    stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
>      ResultSet.CONCUR_READ_ONLY);
>    sql.append("SELECT Someone from Something ");
>    rs = stmt.executeQuery(sql.toString());
>    return rs;
>
>   } catch (SQLException e) {
>    // TODO Auto-generated catch block
>    e.printStackTrace();
>   }
>
>   return rs;
>  }
>
> }
>
> After i collect the rs i close it, but how do i close the connection?

The code isn't so good, that you obtain a connection and don't
retain/manage it. That being said, you can do this in the code
that is closing the result set, instead of closing the result set:

rs.getStatement().getConnection().close();

By spec, closing the connection will close the statement which
will close the result set.

Joe Weinstein

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.databases | Previous | NextPrevious in thread | Find similar


Thread

Close resultset but not t "polilop" <polilop@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
  Re: Close resultset but n joeNOSPAM@BEA.com.remove-dii-this - 2011-04-27 15:22 +0000

csiph-web