码迷,mamicode.com
首页 > 数据库 > 详细

DButils实现查询和新增

时间:2015-09-16 15:50:13      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

    
    public static Adttendance DBSql(String data) throws SQLException {
    String url = "jdbc:mysql://localhost:3306/attendance?useUnicode=true&characterEncoding=utf8";
       String uid = "root";
       String pwd = "";
       Adttendance adttendance=null;
       if (DbUtils.loadDriver("com.mysql.jdbc.Driver")) {
       java.sql.Connection conn = DriverManager.getConnection(url, uid, pwd);
       String sql="select attrs from WT where id =?";
       QueryRunner runner=new QueryRunner();
       adttendance = (Adttendance) runner.query(conn, sql, new BeanHandler<Adttendance>(Adttendance.class), data);  
       System.out.println(adttendance.getAttrs()); 
       DbUtils.close(conn);
      }
    return adttendance;
    }
    
    public static int insertUser(Object schemaID,String data) throws SQLException
    {
        String url = "jdbc:mysql://localhost:3306/attendance?useUnicode=true&characterEncoding=utf8";
        String uid = "root";
        String pwd = "";
        int insertNum = 0;
        if(DbUtils.loadDriver("com.mysql.jdbc.Driver"))
        {
            java.sql.Connection conn = DriverManager.getConnection(url, uid, pwd);
            String sql = "insert into wt values(" + null + ",‘" +schemaID + "‘,‘考勤表‘,‘描述信息‘,‘" + data + "‘,‘kq‘)";
            QueryRunner runner = new QueryRunner();
            insertNum = runner.update(conn, sql);
            // adttendance = runner.query(conn, sql, new BeanHandler<Adttendance>(Adttendance.class), data);
            // System.out.println(adttendance.getAttrs());
            DbUtils.close(conn);
        }
        return insertNum;
    }
    

DButils实现查询和新增

标签:

原文地址:http://www.cnblogs.com/jym-sunshine/p/4813203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!