第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

日夜難眠,看過(guò)jdbc之對(duì)面的女孩走過(guò)來(lái)的幫忙解答一點(diǎn)疑惑

日夜難眠,看過(guò)jdbc之對(duì)面的女孩走過(guò)來(lái)的幫忙解答一點(diǎn)疑惑

Bossen 2016-07-21 10:35:04
里面有個(gè)細(xì)節(jié),困擾我12個(gè)小時(shí)了,我實(shí)在搞不明白,夜里做夢(mèng)都在琢磨,希望有高人能指點(diǎn),早釋疑惑。我在調(diào)用trans(from,to,amout)方法時(shí),老師用的是Account from=null;Account to=null;from=accountDao.get(1);to=accountDao.get(2);這個(gè)里面的get()方法是怎么來(lái)的?直接設(shè)置from和to的Id為什么運(yùn)行時(shí)報(bào)空指針錯(cuò)誤?Account from=new Account();Account to=new Account();from.setId(1);to.setId(2);請(qǐng)求大師解答!跪求解答心中疑惑!
查看完整描述

4 回答

?
Bossen

TA貢獻(xiàn)13條經(jīng)驗(yàn) 獲得超4個(gè)贊

經(jīng)過(guò)24小時(shí)的琢磨,終于弄懂了,我將我犯的錯(cuò)誤放在這里,僅供大家參考,都是一些細(xì)節(jié)的錯(cuò)誤,希望對(duì)大家有所幫助。

//“更新數(shù)據(jù)”方法
public void accountUpdate(Account a) throws Exception{
?Connection conn=DBUtil.getConnection();
?StringBuilder sb=new StringBuilder();
?sb.append("update account_info set account=?,amount=? where id=?");
?PreparedStatement ps=conn.prepareStatement(sb.toString());
?ps.setString(1,a.getAccount());//與上面sql語(yǔ)句對(duì)應(yīng)放在第一個(gè)傳遞
?ps.setDouble(2, a.getAmount());//第二個(gè)傳遞
?ps.setInt(3, a.getId());//第三個(gè)傳遞

?ps.execute();
}
//獲取帶account、id、amount信息的Account對(duì)象
public Account get(Integer id) throws Exception{
?Connection conn=DBUtil.getConnection();
?StringBuilder sb=new StringBuilder();
?sb.append("select id,account,amount from account_info? where id= ?");
?PreparedStatement ps=conn.prepareStatement(sb.toString());
?ps.setInt(1, id);
?ResultSet rs=ps.executeQuery();
?Account a=null;
?while(rs.next()){
??a=new Account();
??a.setId(rs.getInt("id"));
??a.setAccount(rs.getString("account"));
??a.setAmount(rs.getDouble("amount"));
?}
?return a;
?
}

//調(diào)用方法

public class Test01 {
?public static void main ( String[] args ) throws Exception? {
??Service service=new Service();
??AccountAction a=new AccountAction();
??????? Account from=null;
??????? Account to=null;
??????? from=a.get(1);
??????? to=a.get(2);
??????? service.trans(from, to, 20d);
??????? System.out.println("賬戶Id:? "+from.getId()+"賬號(hào):"+from.getAccount()+"????? 余額:"+from.getAmount());
??}
?}

//輸出結(jié)果

賬戶Id:? 1賬號(hào):a????? 余額:210.0

//同時(shí)數(shù)據(jù)庫(kù)中的數(shù)據(jù)也同步更新了。

查看完整回答
1 反對(duì) 回復(fù) 2016-07-21
  • 慕粉3505864
    慕粉3505864
    不看看了想學(xué)著自己操作,但是發(fā)現(xiàn)老師這一集沒(méi)給完整代碼,請(qǐng)問(wèn)你有沒(méi)有源碼分享一下?
?
Bossen

TA貢獻(xiàn)13條經(jīng)驗(yàn) 獲得超4個(gè)贊

定義get()方法,獲取from、to含有id,account、amount信息的對(duì)象

public Account get(Integer id) throws Exception{
?Connection conn=DBUtil.getConnection();
?StringBuilder sb=new StringBuilder();
?sb.append("select id,account,amount from account_info? where id= ?");
?PreparedStatement ps=conn.prepareStatement(sb.toString());
?ps.setInt(1, id);
?ResultSet rs=ps.executeQuery();
?Account a=null;
?while(rs.next()){
??a=new Account();
??a.setId(rs.getInt("id"));
??a.setAccount(rs.getString("account"));
??a.setAmount(rs.getDouble("amount"));
?}
?return a;
?}

//調(diào)用trans(from,to,amount)方法

public class Test01 {
?public static void main ( String[] args ) throws Exception? {
??Service service=new Service();
??AccountAction a=new AccountAction();
??????? Account from=null;
??????? Account to=null;
??????? from=a.get(1);
??????? to=a.get(2);
??????? service.trans(from, to, 20d);
??}
?}

運(yùn)行的時(shí)候沒(méi)有問(wèn)題,大神們過(guò)來(lái)看看,怎么破啊,雖然是個(gè)小問(wèn)題,可是不解決,就不能真正掌握jdbc呀,大家一起探討吧。

查看完整回答
反對(duì) 回復(fù) 2016-07-21
  • 4 回答
  • 1 關(guān)注
  • 1563 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)