一、插入数据
@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方法
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
实践使用Spring JDBC API JdbcTemplate来对MySQL数据库进行增删改查操作
实践使用Spring JDBC API JdbcTemplate来对MySQL数据库进行增删改查操作
sql JdbcTemplate Spring JDBC API MySQL