Connection connection=null;
boolean rollback=false;
try{

  connection=dataSource.getConnection();
  connection.setAutoCommit(false);

  //使用jdbc访问
  
 connection.commit();  

} catch(SQLException e){
  e.printStackTrace();
  rollback=true;
} finally{
 
 if(connection!=null) {
    
	if(rollback) 
	{
	
		try{
		 connection.rollback();
		} catch(SQLException e){
		 e.printStackTrace();  
		}
		
		else{
		
		 try {
		  connection.close(); 
		 }catch(SQLException e){
		  e.printStackTrace();  
		 }
		 
		}
	
	}
    
 }

}

  

相关文章:

  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-08-03
  • 2021-06-21
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-15
  • 2021-10-29
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
  • 2021-09-27
相关资源
相似解决方案