今天我写了Dao层。
public boolean add(User user) {
String sql = "insert into student(id,name,aclass,kecheng,score)"
+ "values('" + user.getId() + "','" + user.getName()+ "','" + user.getAclass() + "','" + user.getKecheng()+ "','" + user.getScore()+ "')";
Connection conn = DBUtil.getConn();//调用方法连接数据库
Statement state = null;//创建一个Statement对象来执行静态的SQL语句
//Statement用于在已经建立数据库连接上发送静态的SQL语句
boolean f = false;
int a = 0 ;
try { //监视大括号内的代码
state = conn.createStatement();//上面的是详解
a = state.executeUpdate(sql);
//执行指定的更新类的SQl语句,并返回操作结果的整型值
} catch (Exception e) { //捕获错误
e.printStackTrace();
} finally {
//关闭z 连接
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}