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;
}
若转载请注明出处!若有疑问,请回复交流!