//可任意创建 这里仅做演示 最好把里实体的一些基本方法写好
package domain;
public class Apple {
private int id;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "id="+id+"\nname="+name+'\n';
}
}
3、对数据库的增删改查操作
对数据库进行增删改查:
ComboPooledDataSource dataSource = new ComboPooledDataSource();
QueryRunner queryRunner = new QueryRunner(dataSource);
// queryRunner.update("delete from apple where id=?",22);//删除
// queryRunner.update("insert into apple values(?,?) ",222,"E");//增加
// queryRunner.update("update apple set id=? where name=?",636,"Z");//改
// Apple apples = queryRunner.query("select * from apple where id=?", new BeanHandler<Apple>(Apple.class),666);
// System.out.println(apples.toString()); //查询单个数据
// List<Apple> applesList = queryRunner.query("select * from apple", new BeanListHandler<Apple>(Apple.class));
// for(Apple apple:applesList){
// System.out.println(apple.toString());
// }//查询多个数据