在更新模块中,如何不需要更新的字段,该如何处理

来源:2-9 JDBC实战---搭建视图层(下)

慕粉0907152656

2017-01-23 16:49

在更新模块中,如何不需要更新的字段,该如何处理

写回答 关注

3回答

  • 芝麻馅的汉堡3374936
    2017-02-16 17:01:39
    /*
    			 * 功能5:更新女神信息
    			 */
    			else if(OPERATION_UPDATE.equals(input.toUpperCase())
    					||OPERATION_UPDATE.substring(0,1).equals(input.toUpperCase())
    					||OPERATION_UPDATE.equals(previous)){
    				previous=OPERATION_UPDATE;
    				if(step==1){
    					System.out.println("请输入要更新的女神编号");
    				}
    				
    				if(step==2){
    					Integer id=null;
    					//第一个try是防止用户输入非数字id
    					try {
    						id=Integer.valueOf(input);
    						goddess=action.get(id);
    						if(goddess==null){
    							System.out.println("查询女信息失败,请输入正确的女神id");
    							step=1;
    						}
    						else{
    							System.out.println("姓名(如果不更新该字段,请输入null):");
    						}
    					} catch (Exception e) {
    						System.out.println("请输入正确的女神id");
    						step=1;
    					}
    				}
    				
    				if(step==3){
    					if(!input.equals("null")){
    						goddess.setUser_name(input);
    					}
    					System.out.println("年龄:");
    				}
    				//输入年龄,提示输入生日
    				if(step==4){
    						Integer age=null;
    						try {
    							if(!input.equals("null")){
    							age=Integer.valueOf(input);
    							goddess.setAge(age);
    							}
    							System.out.println("生日 ,格式:yyyy-MM-dd");
    						} catch (Exception e) {
    							System.out.println("请输入正确的女神年龄:");
    							step=3;
    						}
    				}
    				//输入生日
    				if(step==5){
    						SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    						Date birthday=null;
    						try {
    							if(!input.equals("null")){
    							birthday = sdf.parse(input);
    							goddess.setBirthday(birthday);
    							}
    							System.out.println("邮箱:");
    						} catch (ParseException e) {
    							System.out.println("您输入的格式有误,请重新输入");
    							step=4;
    						}
    				}
    				
    				if(step==6){
    					if(!input.equals("null")){
    						goddess.setEmail(input);
    					}
    					System.out.println("手机号:");
    				}
    				if(step==7){
    					if(!input.equals("null")){
    						goddess.setMobile(input);
    					}
    					try {
    						action.edit(goddess);
    						System.out.println("女神信息更新成功");
    					} catch (Exception e) {
    						System.out.println("女神信息更新失败");
    					}
    					step=1;
    					previous=null;
    				}
    				if(OPERATION_UPDATE.equals(previous)){
    					step++;
    				}


  • 芝麻馅的汉堡3374936
    2017-02-16 17:01:13

    /*

    * 功能5:更新女神信息

    */

    else if(OPERATION_UPDATE.equals(input.toUpperCase())

    ||OPERATION_UPDATE.substring(0,1).equals(input.toUpperCase())

    ||OPERATION_UPDATE.equals(previous)){

    previous=OPERATION_UPDATE;

    if(step==1){

    System.out.println("请输入要更新的女神编号");

    }

    if(step==2){

    Integer id=null;

    //第一个try是防止用户输入非数字id

    try {

    id=Integer.valueOf(input);

    goddess=action.get(id);

    if(goddess==null){

    System.out.println("查询女信息失败,请输入正确的女神id");

    step=1;

    }

    else{

    System.out.println("姓名(如果不更新该字段,请输入null):");

    }

    } catch (Exception e) {

    System.out.println("请输入正确的女神id");

    step=1;

    }

    }

    if(step==3){

    if(!input.equals("null")){

    goddess.setUser_name(input);

    }

    System.out.println("年龄:");

    }

    //输入年龄,提示输入生日

    if(step==4){

    Integer age=null;

    try {

    if(!input.equals("null")){

    age=Integer.valueOf(input);

    goddess.setAge(age);

    }

    System.out.println("生日 ,格式:yyyy-MM-dd");

    } catch (Exception e) {

    System.out.println("请输入正确的女神年龄:");

    step=3;

    }

    }

    //输入生日

    if(step==5){

    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

    Date birthday=null;

    try {

    if(!input.equals("null")){

    birthday = sdf.parse(input);

    goddess.setBirthday(birthday);

    }

    System.out.println("邮箱:");

    } catch (ParseException e) {

    System.out.println("您输入的格式有误,请重新输入");

    step=4;

    }

    }

    if(step==6){

    if(!input.equals("null")){

    goddess.setEmail(input);

    }

    System.out.println("手机号:");

    }

    if(step==7){

    if(!input.equals("null")){

    goddess.setMobile(input);

    }

    try {

    action.edit(goddess);

    System.out.println("女神信息更新成功");

    } catch (Exception e) {

    System.out.println("女神信息更新失败");

    }

    step=1;

    previous=null;

    }

    if(OPERATION_UPDATE.equals(previous)){

    step++;

    }


  • qq_水鬼_0
    2017-01-23 18:23:32

    通过将数据库中对应id 的数据取出来,赋值给不需要更新的字段

JDBC之 “ 对岸的女孩看过来”

一起领略JDBC的奥秘,为进一步学习集成框架打下良好的基础

99327 学习 · 856 问题

查看课程

相似问题