課程
/后端開發(fā)
/Java
/JDBC之 “ 對岸的女孩看過來”
在更新模塊中,如何不需要更新的字段,該如何處理
2017-01-23
源自:JDBC之 “ 對岸的女孩看過來” 2-9
正在回答
/* ?*?功能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("請輸入要更新的女神編號(hào)"); } if(step==2){ Integer?id=null; //第一個(gè)try是防止用戶輸入非數(shù)字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("手機(jī)號(hào):"); } 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++; }
/*
* 功能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("請輸入要更新的女神編號(hào)");
}
if(step==2){
Integer id=null;
//第一個(gè)try是防止用戶輸入非數(shù)字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");
if(step==3){
if(!input.equals("null")){
goddess.setUser_name(input);
System.out.println("年齡:");
//輸入年齡,提示輸入生日
if(step==4){
Integer age=null;
age=Integer.valueOf(input);
goddess.setAge(age);
System.out.println("生日 ,格式:yyyy-MM-dd");
System.out.println("請輸入正確的女神年齡:");
step=3;
//輸入生日
if(step==5){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date birthday=null;
birthday = sdf.parse(input);
goddess.setBirthday(birthday);
System.out.println("郵箱:");
} catch (ParseException e) {
System.out.println("您輸入的格式有誤,請重新輸入");
step=4;
if(step==6){
goddess.setEmail(input);
System.out.println("手機(jī)號(hào):");
if(step==7){
goddess.setMobile(input);
action.edit(goddess);
System.out.println("女神信息更新成功");
System.out.println("女神信息更新失敗");
previous=null;
if(OPERATION_UPDATE.equals(previous)){
step++;
通過將數(shù)據(jù)庫中對應(yīng)id?的數(shù)據(jù)取出來,賦值給不需要更新的字段
舉報(bào)
一起領(lǐng)略JDBC的奧秘,為進(jìn)一步學(xué)習(xí)集成框架打下良好的基礎(chǔ)
1 回答如何新建數(shù)據(jù)庫
1 回答Control更新View???
2 回答在更新女神信息的時(shí)候怎么處理輸入為null的狀況啊
2 回答更新有問題
2 回答啥時(shí)候更新完???
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-02-16
2017-02-16
/*
* 功能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("請輸入要更新的女神編號(hào)");
}
if(step==2){
Integer id=null;
//第一個(gè)try是防止用戶輸入非數(shù)字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("手機(jī)號(hào):");
}
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++;
}
2017-01-23
通過將數(shù)據(jù)庫中對應(yīng)id?的數(shù)據(jù)取出來,賦值給不需要更新的字段