Commons-dbutils is an open source JDBC Tool class library provided by Apache, which is a simple encapsulation of JDBC, very low learning costs, and the use of dbutils can greatly simplify the work of JDBC coding without compromising the performance of the program. As a result, Dbutils is the first choice for many companies that do not like hibernate.
/** * dbutils usage: Use Dbutils to implement additions and deletions change operation * @project_name DAY12 * @class_name DbUtilsDemo1 * @author Dovinya * @data 2014-8 -27 PM 11:07:09 * @version 1 * @notes *//* CREATE DATABASE day12; Use DAY12; CREATE TABLE table1 (ID int primary key auto_increment, name varchar (), salary double); INSERT INTO table1 values (null, ' Zhang ', 234.5); INSERT INTO table1 values (null, ' Li ', 234.5); INSERT INTO table1 values (null, ' Wang ', 3242); INSERT INTO table1 values (null, ' Zhao ', 32543); INSERT INTO table1 values (null, ' Pan ', 4654); INSERT INTO table1 values (null, ' he ', 4235); * */public class DbUtilsDemo1 {/* * use Dbutils to implement change operation */public Void Update () throws SQLException {//Get Data source object Queryrunner Runn ER = new Queryrunner (new Combopooleddatasource ()); Runner.update ("update table1 set salary = 100");} @Testpublic void Add () throws sqlexception{//gets the data source object Queryrunner Runner = new Queryrunner (new Combopooleddatasource ()); Runner.update ("INSERT INTO table1 values (1,?,?)", "Lisi", 1000);} @Testpublic void Delete () throWS sqlexception{//Gets the data source object Queryrunner Runner = new Queryrunner (new Combopooleddatasource ()); Runner.update ("Delete from table1 WHERE name = ' Lisi ');} @Testpublic void Query () throws sqlexception{//get the data source object Queryrunner Runner = new Queryrunner (new Combopooleddatasource ()) ; list<user> list = Runner.query ("Select *from table1 where id<?", New Resultsethandler<list<user>> ( ) {@Overridepublic list<user> handle (ResultSet Rs) throws SQLException {list<user> List = new arraylist< User> (); while (Rs.next ()) {User user = new User (); User.setid (Rs.getint ("id")); User.setname (rs.getstring ("name")); User.setsalary (rs.getdouble ("salary")); List.add (user); return list;}, 5); SYSTEM.OUT.PRINTLN (list); Here you can add breakpoint debugging watch}}
Using Dbutils to implement additions and deletions