First of all, you are making lookup each time and it is not very good.
Second thing, is that your connection will be closed only if no exception
was thrown. For this, try something like:
---------
Connection conn= null;
try{
conn= getConnection(); // your way to get it
//TODO do your job
}catch( Exception ex ){
log.error( ex );
}finally{
if( conn != null ) try{ conn.close(); }catch( SQLException ex ){}
}
---------
Also, what version of Tapestry you are using? For T4 there is much more ways
to work with database ( thru Hivemind mostly ).
Frank wrote:
Hello,
I have this working now that returns the resultset using an ArrayList.
In Tapestry, is this the best way or is there something other than an
ArrayList to use?
Thanks for the help.
Frank
public List doQuery() {
List list = new ArrayList();
try {
Context context = new InitialContext();
DataSource ds = (DataSource)
context.lookup("java:comp/env/jdbc/bankDataSource");
Connection conn = ds.getConnection();
PreparedStatement st = conn.prepareStatement("select *
from accounts");
ResultSet rs = st.executeQuery();
if (rs.next()) {
list.add(createNewItem(rs.getString("accname")));
}
conn.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
return list;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]