怎么就我遇到这种问题! ?
}else if(OPERATION_UPDATE.equals(in.toUpperCase())
|| OPERATION_UPDATE.substring(0,1).equals(in.toUpperCase())
|| OPERATION_UPDATE.equals(previous)){
previous=OPERATION_UPDATE;
//更新
if(1==step){
System.out.println("请输入要更新的女生的【编号/ID】");
}else if(2==step){
try {
if(action.get(Integer.valueOf(in))==null){
System.out.println("ID无效,请重新输入。。。");
step=1;
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
goddess.setId(Integer.valueOf(in));
System.out.println("【姓名】,如果不更新该字段,则输入null,下同");
}else if(3==step){
if(!in.equals("null")){
goddess.setUser_name(in);
}
System.out.println("【性别】 (0:男 , 1:女)");
}else if(4==step){
if(!in.equals("null")){
goddess.setSex(Integer.valueOf(in));
}
System.out.println("【年龄】");
}else if(5==step){
if(!in.equals("null")){
goddess.setAge(Integer.valueOf(in));
}
System.out.println("【生日】,格式如:yyyy-MM-dd");
}else if(6==step){
if(!in.equals("null")){
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
Date birthday=null;
try {
birthday = sf.parse(in);
goddess.setBirthday(birthday);
} catch (ParseException e) {
e.printStackTrace();
System.out.println("您输入的格式有误,请重新输入");
step=5;
}
}
System.out.println("【邮箱】");
}else if(7==step){
if(!in.equals("null")){
goddess.setEmail(in);
}
System.out.println("【手机号】");
}else if(8==step){
if(!in.equals("null")){
goddess.setMobile(in);
}
try {
action.edit(goddess);
System.out.println("女生信息更新成功!");
previous=null;
} catch (Exception e) {
e.printStackTrace();
System.out.println("女生信息更新失败!\n"+"请重新输入。。。");
step=0;
}
}
if(OPERATION_UPDATE.equals(previous)){
step++;
}
}
如图,2个问题。谁能助我,感激不尽!
我还疑惑的是,在原始的updateGoddess()方法中,只有9个参数,代码如下:
public void updateGoddess(Goddess g) throws SQLException{
Connection conn=DBUtil.getConnection();
String sql="update imooc_goddess set user_name=?,sex=?,age=?,birthday=?,email=?,mobile=?,"
+ "update_user=?,update_date=current_date(),isdel=? "
+ "where id=?";
PreparedStatement ptmt=conn.prepareStatement(sql);
ptmt.setString(1, g.getUser_name());
ptmt.setInt(2, g.getSex());
ptmt.setInt(3, g.getAge());
ptmt.setDate(4, new Date(g.getBirthday().getTime()));
ptmt.setString(5, g.getEmail());
ptmt.setString(6, g.getMobile());
ptmt.setString(7, g.getUpdate_user());
ptmt.setInt(8, g.getIsdel());
ptmt.setInt(9, g.getId());
ptmt.execute();
}而我在View中的update模块里,不论是按视频里写ID加姓名、年龄、生日这4个参数,还是对照updateGoddess()写9个,或是写完全部12个参数,都报空指针异常。这是为什么?