public void add() throws SQLException{ QueryRunner runner = new MyQueryRunner(new ComboPooledDataSource()); runner.update("insert into account values(null,?,?)","c",1000); }
public void del() throws SQLException{ QueryRunner runner = new MyQueryRunner(new ComboPooledDataSource()); runner.update("delete from account where id=?",3); }
public void update() throws SQLException{ QueryRunner runner = new MyQueryRunner(new ComboPooledDataSource()); runner.update("update account set money=? where name=?", 777,"a"); }
1.ScalarHandler:获取结果集中第一行数据指定列的值,经常使用来进行单值查询segmentfault
public void test() throws SQLException{ QueryRunner runner = new QueryRunner(new ComboPooledDataSource()); Long count = (Long)runner.query("select count(*) from account",new ScalarHandler()); System.out.println(count); }
2.BeanHandler:将结果集中的第一行数据封装到一个对应的JavaBean实例中code
public void test() throws SQLException{ QueryRunner runner = new QueryRunner(new ComboPooledDataSource()); Account acc = runner.query("select * from account where money>?", new BeanHandler<Account>(Account.class),500); System.out.println(acc); }
3.BeanListHandler:将结果集中的每一行数据都封装到一个对应的JavaBean实例中,存放到List里。get
public void test() throws SQLException{ QueryRunner runner = new QueryRunner(new ComboPooledDataSource()); List<Account>list = runner.query("select * from account where money>?", new BeanListHandler<Account>(Account.class),500); System.out.println(list); }
客户查询系统(https://segmentfault.com/a/11...io