浪费别人的时间等于是谋财害命,浪费自己的时间等于是慢性自杀。 —— 列宁

DButils实现查询和新增

    
    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;
    }
    
posted @ 2015-09-16 14:12  一谦的视界  阅读(468)  评论(0编辑  收藏  举报