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执行指定名称的存储过程。代码展示了如何设置自动提交模式、执行存储过程及处理异常。

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



