w new SQLException("execute error");
}
}
[JAVA100例]059、事务处理(2)
时间:2011-01-09
/**
*<br>方法说明:实例演示
*<br>输入参数:
*<br>返回类型:
*/
public void demo(){
JDBCConnCommit oc = new JDBCConnCommit();
Connection conn = oc.conn();
try{
conn.setAutoCommit( false );
String sql = "";
for(int i=0;i<4;i++){
sql = "insert into TBL_USER(id,name,password)values(seq_user.nextval,´tom´,´haorenpingan´)";
oc.execute(conn,sql);
}
sql = "select * from TBL_USER where name=´tom´ order by id";
oc.query(conn,sql);
sql = "delete from TBL_USER where name=´tom´";
oc.execute(conn,sql);
conn.commit();
}catch(SQLException se){
try{
conn.rollback();
}catch(Exception e){
}
System.out.println(se);
}catch(Exception e){
System.out.println(e);
}finally
{
try{
conn.close();
}catch(SQLException e){}
}
}
/**
*<br>方法说明:主方法
*<br>输入参数:
*<br>返回类型:
*/
public static void main(String[] arg){
if(arg.length!=3){
System.out.println("use: java JDBCConnCommit url username password");
return;
}
JDBCConnCommit oc = new JDBCConnCommit();
oc.url = arg[0];
oc.username=arg[1];
oc.password=arg[2];
oc.demo();
}
}
|