|
Hi all,
I'm writing a DAO and using the xpetstore
application for some guidance.
However, I think I may have found a
bug.
The xpetstore uses a session facade to search for
particular products. It
contains two methods used for this - one to get the
database connection,
and the other to invoke the a DAO with the search
parameters - really nice
and simple:
//------------- session facade
methods-----------------------------
/**
* @ejb.interface-method * @ejb.transaction * type="NotSupported" */ public Page searchProducts( String key, int start, int count ) { try { ProductDAO dao = new ProductDAO( getConnection() ); return dao.findByKey( "%" + key + "%", start, count ); } catch( SQLException sql ) { throw new EJBException( sql ); } } private Connection getConnection() { try { InitialContext ic = new InitialContext(); DataSource ds = ( DataSource )ic.lookup( JNDINames.DATASOURCE ); return ds.getConnection(); } catch( Exception e ) { throw new EJBException(); } } //------------- DAO method
----------------------------- public ProductDAO( Connection
cnn )
{ _cnn = cnn; } public Page findByKey( String
key, int start, int count )
throws SQLException { PreparedStatement stmt = _cnn.prepareStatement ( SQL_FIND_BY_KEY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
stmt.setString ( 1, key );
stmt.setString ( 2, key ); stmt.setString ( 3, key );
ResultSet rs = stmt.executeQuery ( );
return
toPage ( rs, start, count );
} However, my question is - why isn't the database
connection getting closed?
Should it be getting closed?
thanks very much,
Brian
|
- RE: [JBoss-user] Closing database connections Brian McSweeney
- RE: [JBoss-user] Closing database connections Martin Vilcans
- Re: [JBoss-user] Closing database connections Brian McSweeney
- Re: [JBoss-user] Closing database connectio... Herve Tchepannou
- RE: [JBoss-user] Closing database connectio... Martin Vilcans
- Re: [JBoss-user] Closing database conne... Brian McSweeney
- RE: [JBoss-user] Closing database connections Enrique Rodr�guez
- Re: [JBoss-user] Closing database connections Brian McSweeney
- RE: [JBoss-user] Closing database connections Alastair Rodgers
- Re: [JBoss-user] Closing database connections Brian McSweeney
