今天早上百度了一早上,还是没用找到spring对纯jdbc事务的支持相关资料
这儿的纯jdbc指的是类似如下代码: /**
*
* 执行SQL语句,返回影响的结果数
*
*
*
* @param sql
*
* @return
*
* @throws Exception
*
*/
public int executeSQL(String sql) throws Exception {
PreparedStatement pstmt = null;
Connection dbConnection = null;
logSqlStatement(sql);
try {
dbConnection = JdbcUtils.getConnection();
pstmt = dbConnection.prepareStatement(sql);
int cnt = pstmt.executeUpdate();
return cnt;
} catch (SQLException ex) {
throw new DAOException("executeSQL时出错:" + ex.getMessage(), ex);
} finally {
DAOUtils.close(dbConnection, pstmt);
}
}不是要对hibernate和jdbctemplate 的事务支持,求解
这儿的纯jdbc指的是类似如下代码: /**
*
* 执行SQL语句,返回影响的结果数
*
*
*
* @param sql
*
* @return
*
* @throws Exception
*
*/
public int executeSQL(String sql) throws Exception {
PreparedStatement pstmt = null;
Connection dbConnection = null;
logSqlStatement(sql);
try {
dbConnection = JdbcUtils.getConnection();
pstmt = dbConnection.prepareStatement(sql);
int cnt = pstmt.executeUpdate();
return cnt;
} catch (SQLException ex) {
throw new DAOException("executeSQL时出错:" + ex.getMessage(), ex);
} finally {
DAOUtils.close(dbConnection, pstmt);
}
}不是要对hibernate和jdbctemplate 的事务支持,求解
conn.setAutoCommit(false);
然后
conn.commit(); 或者conn.rollback();
类似:conn.setAutoCommit(false);
然后
conn.commit(); 或者conn.rollback();
这样的代码,只能放在dao里面