zoukankan      html  css  js  c++  java
  • 增删改查

    一、插入数据
    @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方法

  • 相关阅读:
    思考
    创建Windows Mobile上兼容性好的UI 程序
    中文乱码(二)
    中文乱码(三)
    MySQL字符集产生乱码的简单讲解
    MySql乱码解决(五)
    中文乱码(四)
    mysql中文问题全处理
    Linux 中 x86 的内联汇编
    arm下的gcc内联汇编
  • 原文地址:https://www.cnblogs.com/wsx123/p/13745871.html
Copyright © 2011-2022 走看看