Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.databases > #263 > unrolled thread
| Started by | "polilop" <polilop@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:22 +0000 |
| Last post | 2011-04-27 15:22 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.java.databases
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
| From | "polilop" <polilop@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:22 +0000 |
| Subject | Close resultset but not t |
| Message-ID | <gbtr3j$lbj$1@ss408.t-com.hr> |
To: comp.lang.java.databases
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?
---
* 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
[toc] | [next] | [standalone]
| From | joeNOSPAM@BEA.com.remove-dii-this |
|---|---|
| Date | 2011-04-27 15:22 +0000 |
| Subject | Re: Close resultset but n |
| Message-ID | <90816268-847f-4656-9d2f-6ac3b2af1533@x35g2000hsb.googlegroups.com> |
| In reply to | #263 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.databases
csiph-web