[jboss-user] [EJB 3.0] - JDBC close
xmedeko
do-not-reply at jboss.com
Mon Mar 23 08:40:46 EDT 2009
Hi,
I use JDBC in a stateless session bean. (I know it's a bad practice.) I get the connection via the JBoss DataSource
try {
InitialContext ic = new InitialContext();
dataSource = (DataSource) ic.lookup("java:/testDS");
Connecion conn = dataSource.getConnection();
PreparedStatement ps = ...
ResultSet rs = ps.executeStatemet();
} catch (SQLException e) {
LOG(...);
throw new EJBException(e);
} finally {
DBUtils.close(rs);
DBUtils.close(ps);
DBUtils.close(conn);
}
I am not sure, whether is it the right thing to close all JDBC resources in the finally clause? AFAIK the container makes a rollback in case of any exception. But I do not know, if the container also cleans everything up as well? E.g. would be sufficient
try {
InitialContext ic = new InitialContext();
dataSource = (DataSource) ic.lookup("java:/testDS");
Connecion conn = dataSource.getConnection();
PreparedStatement ps = ...
ResultSet rs = ps.executeStatemet();
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
LOG(...);
throw new EJBException(e);
}
Thank you
Andy
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4220215#4220215
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4220215
More information about the jboss-user
mailing list