public boolean exepro(String proname) {
DataSource logdao = (DataSource) ComponentFactory.getBean("dataSource");
Connection con = null;
CallableStatement csmt = null;
try {
con = logdao.getConnection();
log.info("-----------kaishi"+proname);
con.setAutoCommit(true);
csmt = con.prepareCall(proname);
csmt.executeUpdate();
con.setAutoCommit(false);
con.commit();
log.info("-----------jieshu"+proname);
} catch (Exception e) {
log.error("resetRecord Error:" + e.getMessage());
return false;
} finally {
if (csmt != null) {
try {
csmt.close();
} catch (Exception e) {
log.error("关闭PreparedStatement出错:" + e.getMessage());
}
}
if (con != null) {
try {
con.close();
} catch (Exception e) {
log.error("关闭Connection出错:" + e.getMessage());
}
}
}
return true;
}
本文介绍了一个使用Java执行数据库存储过程的示例代码,通过DataSource获取数据库连接,并使用CallableStatement来调用存储过程。该过程包括设置自动提交、执行存储过程、提交更改以及异常处理等关键步骤。

1084

被折叠的 条评论
为什么被折叠?



