一、插入数据
@Test
public void insert() throws SQLException{
QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
String sql ="INSERT INTO product VALUES(6,'米饭',0.2)";
int insert = queryRunner.update(sql);
System.out.println("成功插入"+ insert +"条");
}
二、查询
@Test
public void select() throws SQLException{
QueryRunner query = new QueryRunner(C3P0Utils.getDataSource());
String sql= "select * from product";
List<Product> dt = query.query(sql,new BeanListHandler<Product>(Product.class));
System.out.println(dt);
}
三、修改
@Test
public void update4() throws SQLException{
QueryRunner queryrunner = new QueryRunner(C3P0Utils.getDataSource());
String sql = "update product set pname='老三',price=12232 where pid=4";
int update = queryrunner.update(sql);
System.out.println("成功修改"+update+"条");
}
四、删除
@Test
public void delete() throws SQLException{
QueryRunner run = new QueryRunner(C3P0Utils.getDataSource());
String sql2 = "delete from product where pid=? ";
Object [] parmes = {2};
int re = run.update(sql2,parmes);
System.out.println(re);
}
@test:代替main方法