Closing the statement closes the resultSet.

---------------------
I agree that the Statement and the PreparedStatement must be explicitly
closed. But what about the
ResultSet. How come the following piece of code works?

try{
 for(int i=0;i<1000;i++)
  WRes.selectInfoProd(connection,182);
}catch(Exception e){out.print(e);throw e;};
public static BaseEB selectInfoProd(Connection c,int id) throws Exception{
PreparedStatement ps = null;
InfoProd bean = new InfoProd();
try{
ps = c.prepareStatement(selInfoProd);
ps.setInt(1,id);
ResultSet rs = ps.executeQuery();
if (rs.next()){
bean.setId(id);
bean.setName(rs.getString(1));
bean.setDate(rs.getDate(2));
bean.setDescription(WBNames.readClob(rs,"descr"));
bean.setOwner(rs.getInt(4));
bean.setEditor(rs.getString(5));
}else return null;
return bean;
}catch(Exception e){throw e;}
finally{
if (ps!=null)
ps.close();
}
}

public final static String readClob(java.sql.ResultSet rs, String colName)
throws Exception {
String ret = null;
switch (WBNames.DBSERVER_TYPE) {
case WBNames.DB_SERVER_ORACLE :
java.io.Reader in = null;
java.sql.Clob clob = rs.getClob(colName);
if (clob == null)
return null;
in = clob.getCharacterStream();
char[] c = new char[(int) clob.length()];
int count = in.read(c, 0, c.length);
in.close();
in = null;
if (count == -1) {
c = null;
try {
in.close();
} catch (Exception ignored) {
}

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to