java 事务提交/回滚

1.1        事务实例

 java.sql.Connection;import

 java.sql.Statement; 

  RunInsert {       

*@paramargs     

publicstaticvoid

null

null

try

// 动态导入数据库的驱动           Class.forName(); 

// 获取数据库链接           conn = DriverManager.getConnection(                  );                     

false 

// 创造

"INSERT INTO user_list ( user_name, user_password ) VALUES ( 'Eric', '123' )"

           SQL语句           stmt = conn.createStatement();           stmt.executeUpdate(sql);                     

out"OK!"

catch

// 回滚事务            {              conn.rollback();            ( Exception e2 ) {}

finally

// 关闭

try

catch

// 关闭

try

catch

}

你可能感兴趣的:(数据库,java,事务,提交,回滚)