请模拟银行转账原理,把A账户上的钱转账给B账户,;
解决方案 »
- 断网出现org.springframework.beans.factory.BeanDefinitionStoreException: IOException
- 管理浏览器的问题
- 高手请讲!
- 用过基于lucene的regain的进来帮忙看个问题
- jsp在eclipse中的问题
- 水晶报表加载过程中总是提示异常:某些参数缺少值
- 无法更新网页内容,求助
- servlet获取byte数组
- tomcat 4.1.29 乱码问题??!!!!
- ERROR org.apache.struts2.dispatcher.Dispatcher - Dispatcher initialization faile
- hibernate spring集成做事务管理的时候异常
- 关于时间相减的问题
conn.setAutoCommit(false);
....
...
if(成功)
conn.commit();
else
conn.rollback();最后
conn.setAutoCommit(true);
st=conn.createStatment();
sql="...";
st.addBatch();
sql="...";
st.addBatch();
st.excuteBatch();
conn.commit();
+1
可以尝试用下 addBatch()
去调用。
你把Connection的autoCommit设置为false,
两个都成功了再conn.commit吧.!
IConnection icon = null;
ICallableStatement cs = null;
int ret = -10000;
try {
icon = DbFactory.getInstance().getConnection(DBI.GLOBAL.DB);
icon.setAutoCommit(false);
cs = icon.prepareCall(proc_ins_publishers);
cs.setString(1, po.getPublisherID());
cs.setString(2, po.getUserID());
cs.setString(3, po.getLoginName());
cs.setString(4, po.getName());
cs.setString(5, po.getContactName());
cs.setString(6, po.getAddress());
cs.setString(7, po.getPhone());
cs.setString(8, po.getMobile());
cs.setString(9, po.getUserType());
cs.setString(10, po.getFax());
cs.setString(11, po.getZipCode());
cs.setString(12, po.getEmail());
cs.registerOutParameter(13, Types.INTEGER);
cs.execute();
ret = cs.getInt(13);
if (ret == 1) {
cs.close();
cs = icon.prepareCall(proc_ins_lnk_pub_dest);
String[] lst = po.getDests().split(",");
for (int i = 0; i < lst.length && !lst[i].equals(""); i++) {
cs.setString(1, po.getPublisherID());
cs.setInt(2, Integer.parseInt(lst[i]));
cs.registerOutParameter(3, Types.INTEGER);
cs.execute();
ret = cs.getInt(3);
if (ret == -1) {
throw new Exception("DB Error!");
}
}
} else if (ret == -2) {
throw new Exception("Dup_Name Error!");
} else {
throw new Exception("DB Error!");
}
icon.commit();
} catch (Exception e) {
if (icon != null) {
try {
icon.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
e.printStackTrace();
} finally { if (cs != null) {
try {
cs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (icon != null) {
try {
icon.setAutoCommit(true);
} catch (SQLException e) {
e.printStackTrace();
}
try {
icon.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return ret;
}
dml(增加,删除,修改)语句都用executeUpdate()方法吗
executeUpdate()与executeUpdate(String sql)方法有什么区别呢;好像没有吧
boolean temp=true;
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.addBatch(sql);
stmt.addBatch(sql2);
stmt.executeBatch();
conn.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
temp=false;
// 回滚
try {
conn.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return temp;
}