首页 > 代码库 > javaweb中为mysql的curd多个值的语句
javaweb中为mysql的curd多个值的语句
更新语句
String sql = "update student set num=?,name=?,birthday=?,score=?,password=? where id=?";
ps = conn.prepareStatement(sql);
ps.setString(1, student.getNum());
ps.setString(2, student.getName());
ps.setString(3, student.getBirthday2());
ps.setDouble(4, student.getScore());
ps.setString(5, student.getPassword());
ps.setInt(6, id);
删除
String sql="delete from student where id=?";
ps=conn.prepareStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
插入
String sql = "insert into student(num,name,birthday,score,password) values(?,?,?,?,?)";
ps = conn.prepareStatement(sql);
ps.setString(1, student.getNum());
ps.setString(2, student.getName());
ps.setDouble(4, student.getScore());
ps.setString(5, student.getPassword());
ps.setString(3, student.getBirthday2());
查询
String sql = "select * from student where num=? and password=?";
// 获取DB操作对象
ps = conn.prepareStatement(sql);
// 为动态参数赋值
ps.setString(1, num);
ps.setString(2, password);
javaweb中为mysql的curd多个值的语句