详细解决方案
请教各位,使用PreparedStatement mysql 数据库 不回滚,盼望解答。多谢。 具体如上
热度:1865 发布时间:2013-02-25 21:15:44
mysql5 不发生异常时功能正常,有异常时,不回滚
public void copyInfoToEditPublishFromGather(String id){
String sql = " INSERT INTO table_edit_information" +
" (information_title, information) " +
" select " +
" information_title , information" +
" from table_gather_information" +
" WHERE ID = " +id ;
String sqlUpdateEdit = "UPDATE table_edit_information SET publish = 1 WHERE id_gather = " + id;
String sqlUpdateGather = "UPDATE table_gather_information SET use_status = 1 WHERE ID = " + id;
try{
conn.setAutoCommit(false);
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.executeUpdate();
psmt = null;
psmt = conn.prepareStatement(sqlUpdateEdit);
//psmt.addBatch();
psmt.executeUpdate();
psmt = null;
psmt = conn.prepareStatement(sqlUpdateGather);
psmt.addBatch();
psmt.executeUpdate();
//psmt.executeUpdate(sqlUpdateEdit);
//psmt.executeUpdate(sqlUpdateGather);
conn.commit(); //提交事务
psmt.close();
conn.close();
}catch(Exception e) {
try{
conn.rollback();
}catch(SQLException r){
System.out.println(r.getMessage());
}
System.out.println(e.getMessage());
}
}
------解决方案--------------------------------------------------------
try{
conn.rollback();
}catch(SQLException r){
System.out.println(r.getMessage());
去掉这里的try/catch
------解决方案--------------------------------------------------------
try{
在这里打印一下看看他有没有进来
conn.rollback();
}catch(SQLException r){
System.out.println(r.getMessage());
}
相关解决方案
- mysql 简单化 or能否实现
- 请问registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister
- MySQL 5.5 Command Line Client 窗口1输密码就退出
- 请问上Linux平台上怎么搭建JDK \TOMCAT\MYSQL
- 在LINUX上配置 MySQL 开机自动 启动
- mysql 转 orocle java ssh项目一条 sql 句不通!
- 急求帮忙!mysql 【 Column count doesn't match value count 】,该怎么解决
- jsp中的注册登录系统(mysql)
- 上了个 MySQL 5.5.25 但是安装时出错了
- 求jsp博客源代码mvc+mysql,该如何解决
- java mysql 中文乱码有关问题
- 请教各位,使用PreparedStatement mysql 数据库 不回滚,盼望解答。多谢。 具体如上
- mysql Statement parameter 一 not set
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306,该怎么处理
- MyBatis 读取 Mysql Blob类型的SQL如何写呢
- JDBC MYSQL 驱动加载失败 JSP DAO ECLIPSE,该怎么解决
- Only a type can be imported. com.mysql.jdbc.Driver resolves to a package解决方案
- tomcat 中抛异com.mysql.jdbc.exceptions.MySQLTransactionRollbackException,该如何处理
- struts+iBatis+mysql,该如何解决
- mysql 有外键的插入解决方案
- JSP 更新 MySQL 语句时遇到异常了= =
- PreparedStatement pstmt=conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);oracle出现java.sql.SQLException: 不支持的特性的异常,什么原因
- mysql,该如何处理
- +++++ mysql 插入成功,查询不到记录?
- MyBatis3.1.1 Insert 回到主键 long类型 MYSQL 数据库
- mysql:假若一个表中,有两个属性name和id,删除同名的保留id小的,问这样写有误吗
- PreparedStatement 有关问题
- java mysql where限制有关问题
- mysql 数据库,如果信息存在调出,如果不存在转到另一个jsp中解决思路
- mysql jdbc的配置解决方案