Skip to content

gp15237125756/DbUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple usage for apache's DbUtils project

Notion

When use the apache DbUtils ,one must take care the transaction problem. Basicalliy,if u specify connection through param,u have to manually invoke submit() and close() method. Just like below codes in sevice layor.

Dao layor:

	QueryRunner runner=new QueryRunner();
	Long result=runner.insert(DbUtils.getConnection(),sql, new ScalarHandler<Long>(),"ivanka Trump",30,false,false);

Service layor:

	 public void insert() throws SQLException{
			 try{
				 WomanDao dao=new WomanDao();
				 dao.insert();
				 DbUtils.submit();
			 }catch(Exception e){
				 e.printStackTrace();
				 DbUtils.rollback();
			 }finally{
				 DbUtils.closeConnection();
			 }
		 }

oppositely,if u specify DataSource through below code,then DbUtils will autocommit and autoClose the connection.

Dao layor:

QueryRunner runner=new QueryRunner(dataSource);
Long result=runner.insert(sql, new ScalarHandler<Long>(),"ivanka Trump",30,false,false);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages