Java中事务处理方法
2008-02-01 21:05
274 查看
public boolean addSeatInfo(TSeatInfo ts,String OrderDetailID)throws Exception
{
boolean b=false;
Connection conn=null;
PreparedStatement ps = null;
Statement st = null;
ResultSet rs=null;
try
{
conn = DBMgr.getInstance().getConn();
conn.setAutoCommit(false);
String sql="insert into t_seat_info(seq_seat_info_id,Creator,CreateTime,SeatDesc,WhichSell,WhoSell,WhenSell,Num)"
+"values(seq_seat_info.nextval,?,sysdate,?,?,?,sysdate,?)";
ps = conn.prepareStatement(sql);
ps.setString(1,ts.getCreator());
ps.setString(2,ts.getSeatDesc());
ps.setString(3,ts.getWhichSell());
ps.setString(4,ts.getWhoSell());
ps.setFloat(5,ts.getNum());
ps.executeUpdate();
st = conn.createStatement();
String key="";
rs= st.executeQuery("select seq_seat_info.currval from dual");
if(rs.next())
{
key=rs.getString(1);
}
sql="update t_order_detail set seq_seat_info_id=? where seq_order_detail_id=?";
ps = conn.prepareStatement(sql);
ps.setString(1,key);
ps.setString(2,OrderDetailID);
ps.executeUpdate();
conn.commit();
b=true;
}
catch(Exception e)
{
conn.rollback();
e.printStackTrace();
}
finally
{
if(ps!=null)
{
ps.close();
}
if(st!=null)
{
st.close();
}
if(rs!=null)
{
rs.close();
}
conn.setAutoCommit(true);
DBMgr.closeCon(conn);
}
return b;
}
{
boolean b=false;
Connection conn=null;
PreparedStatement ps = null;
Statement st = null;
ResultSet rs=null;
try
{
conn = DBMgr.getInstance().getConn();
conn.setAutoCommit(false);
String sql="insert into t_seat_info(seq_seat_info_id,Creator,CreateTime,SeatDesc,WhichSell,WhoSell,WhenSell,Num)"
+"values(seq_seat_info.nextval,?,sysdate,?,?,?,sysdate,?)";
ps = conn.prepareStatement(sql);
ps.setString(1,ts.getCreator());
ps.setString(2,ts.getSeatDesc());
ps.setString(3,ts.getWhichSell());
ps.setString(4,ts.getWhoSell());
ps.setFloat(5,ts.getNum());
ps.executeUpdate();
st = conn.createStatement();
String key="";
rs= st.executeQuery("select seq_seat_info.currval from dual");
if(rs.next())
{
key=rs.getString(1);
}
sql="update t_order_detail set seq_seat_info_id=? where seq_order_detail_id=?";
ps = conn.prepareStatement(sql);
ps.setString(1,key);
ps.setString(2,OrderDetailID);
ps.executeUpdate();
conn.commit();
b=true;
}
catch(Exception e)
{
conn.rollback();
e.printStackTrace();
}
finally
{
if(ps!=null)
{
ps.close();
}
if(st!=null)
{
st.close();
}
if(rs!=null)
{
rs.close();
}
conn.setAutoCommit(true);
DBMgr.closeCon(conn);
}
return b;
}
相关文章推荐
- java 数据事务处理 (必须在同一个连接,跨连接此方法无效,得用JPA)
- java分布式事务的一种简单处理方法
- opensession()和getCurrentSession()方法的区别(JTA(java Transaction Api,分布式事务)事务和Connection事务:数据库自带的事务处理方式)
- JAVA 中URL链接中文参数乱码的处理方法JAVA 中URL链接中文参数乱码的处理方法
- JS 对java返回的json格式的数据处理方法
- JNI:Java调用C/C++-传递空值(null)的处理方法
- JAVA 中URL链接中文参数乱码的处理方法
- JAVA设计模式-事务处理
- java处理日期时间的方法
- ASP.Net中的事务处理的几种方法
- Java异常及处理方法
- JAVA处理日期时间常用方法详解
- java处理大文本及复杂文本替换方法
- ASP实现数据库事务处理的方法
- JAVA学习笔记25——异常机制1:Exception简介+异常处理的try_catch_finally方法
- 工作之余,整理了一下平时处理数据的一些常用的,简单的方法。希望对学习JAVA的朋友有点帮助
- 爪哇(Java)自定义的二个字符串高效处理方法,在静寂一个半月之后 推荐
- 利用ASP实现事务处理的方法-转
- JAVA UTF-8 处理方法
- MySQL不支持事务处理的解决方法