課程
/后端開發(fā)
/Java
/JDBC之“對岸的女孩走過來”
求源代碼,,謝。我定好好學(xué)習(xí)
2016-12-06
源自:JDBC之“對岸的女孩走過來” 3-3
正在回答
package?com.xiong.lq.dao; import?java.sql.Connection; import?java.sql.PreparedStatement; import?java.sql.ResultSet; import?java.sql.SQLException; import?java.util.ArrayList; import?java.util.List; import?com.xiong.lq.db.C3P0Util; import?com.xiong.lq.db.DBCPUtil; import?com.xiong.lq.db.DB_util; import?com.xiong.lq.model.Account; public?class?AccountDAO?{ ?public?void?insert(Account?account)?throws?SQLException{ ??Connection?conn?=DB_util.getConnection(); ??PreparedStatement?st?=conn.prepareStatement("insert?into?account_info(account,amount)?values?(?,?)"); ??st.setString(1,?account.getAccount()); ??st.setDouble(2,?account.getAmount()); ??st.execute(); ?} ?public?void?update(Account?account)?throws?SQLException{ ??Connection?conn?=DB_util.getConnection(); ??PreparedStatement?st?=conn.prepareStatement("update?account_info?set?account?=?,amount=??where?id?=?"); ??st.setString(1,?account.getAccount()); ??st.setDouble(2,?account.getAmount()); ??st.setInt(3,?account.getId()); ??st.execute(); ?} ?public?void?delete(Account?account)?throws?SQLException{ ??Connection?conn?=DB_util.getConnection(); ??PreparedStatement?st?=conn.prepareStatement("delete?from?account_info?where?id?=?"); ??st.setInt(1,?account.getId()); ??st.execute(); ?} ?public?List<Account>?query(Account?account)?throws?SQLException{ ??List<Account>?list?=new?ArrayList<Account>(); ??Connection?conn?=DB_util.getConnection(); ??StringBuilder?sb?=new?StringBuilder(); ??sb.append("select?*?from?account_info"); ??sb.append("where?account?like??"); ??PreparedStatement?st?=conn.prepareStatement(sb.toString()); ??st.setString(1,?"%"+account.getAccount()+"%"); ??ResultSet?rs?=st.executeQuery(); ??Account?a?=null; ??while(rs.next()){ ???a=new?Account(); ???a.setAccount(rs.getString("account")); ???a.setAmount(rs.getDouble("amount")); ???a.setCreate_at(rs.getDate("create_at")); ???a.setId(rs.getInt("id")); ???list.add(a); ??} ??return?list; ?} ?public?Account?query(int?id)?throws?SQLException{ ??List<Account>?list?=new?ArrayList<Account>(); ??Connection?conn?=DB_util.getConnection(); ??StringBuilder?sb?=new?StringBuilder(); ??sb.append("select?*?from?account_info"); ??sb.append("?where?id?like??"); ??PreparedStatement?st?=conn.prepareStatement(sb.toString()); ??st.setInt(1,?id); ??ResultSet?rs?=st.executeQuery(); ??Account?a?=null; ??while(rs.next()){ ???a=new?Account(); ???a.setAccount(rs.getString("account")); ???a.setAmount(rs.getDouble("amount")); ???a.setCreate_at(rs.getDate("create_at")); ???a.setId(rs.getInt("id")); //???list.add(a); ??} ??return?a; ?} ? ?public?Account?queryByDbcp(int?id)?throws?SQLException{ ??DBCPUtil?db?=new?DBCPUtil(); ??List<Account>?list?=new?ArrayList<Account>(); ??Connection?conn?=db.getConn(); ??StringBuilder?sb?=new?StringBuilder(); ??sb.append("select?*?from?account_info"); ??sb.append("?where?id?like??"); ??PreparedStatement?st?=conn.prepareStatement(sb.toString()); ??st.setInt(1,?id); ??ResultSet?rs?=st.executeQuery(); ??Account?a?=null; ??while(rs.next()){ ???a=new?Account(); ???a.setAccount(rs.getString("account")); ???a.setAmount(rs.getDouble("amount")); ???a.setCreate_at(rs.getDate("create_at")); ???a.setId(rs.getInt("id")); //???list.add(a); ??} ??return?a; ?} ?public?Account?queryByC3P0(int?id)?throws?SQLException{ ??C3P0Util?c3p0?=new?C3P0Util(); ??List<Account>?list?=new?ArrayList<Account>(); ??Connection?conn?=c3p0.getConnection(); ??StringBuilder?sb?=new?StringBuilder(); ??sb.append("select?*?from?account_info"); ??sb.append("?where?id?like??"); ??PreparedStatement?st?=conn.prepareStatement(sb.toString()); ??st.setInt(1,?id); ??ResultSet?rs?=st.executeQuery(); ??Account?a?=null; ??while(rs.next()){ ???a=new?Account(); ???a.setAccount(rs.getString("account")); ???a.setAmount(rs.getDouble("amount")); ???a.setCreate_at(rs.getDate("create_at")); ???a.setId(rs.getInt("id")); //???list.add(a); ??} ??return?a; ?} } package?com.xiong.lq.dao; import?java.sql.Connection; import?java.sql.PreparedStatement; import?java.sql.ResultSet; import?java.sql.SQLException; import?java.util.ArrayList; import?java.util.List; import?com.xiong.lq.db.DB_util; import?com.xiong.lq.model.TransInfo; public?class?TransInfoDAO?{ ?public?void?insert(TransInfo?transInfo)?throws?SQLException{ ??Connection?conn?=DB_util.getConnection(); ??PreparedStatement?st?=conn.prepareStatement("insert?into?trans_info(source_id,source_account,destination_id,destination_account,amount)?values(?,?,?,?,?)"); ??st.setInt(1,?transInfo.getSource_id()); ??st.setString(2,?transInfo.getSource_account()); ??st.setInt(3,?transInfo.getDesitination_id()); ??st.setString(4,?transInfo.getDesitination_account()); ??st.setDouble(5,?transInfo.getAmount()); ??st.execute(); ?} ?public?void?update(TransInfo?transInfo)?throws?SQLException{ ??Connection?conn?=DB_util.getConnection(); ??PreparedStatement?st?=conn.prepareStatement("update?trans_info?set?source_id?=?,source_account?=?,destination_id?=?,destination_account=?,amount=??where?id?=?"); ??st.setInt(1,?transInfo.getSource_id()); ??st.setString(2,?transInfo.getSource_account()); ??st.setInt(3,?transInfo.getDesitination_id()); ??st.setString(4,?transInfo.getDesitination_account()); ??st.setDouble(5,?transInfo.getAmount()); ??st.setInt(6,?transInfo.getId()); ??st.execute(); ?} ?public?void?delete(TransInfo?transInfo)?throws?SQLException{ ??Connection?conn?=DB_util.getConnection(); ??PreparedStatement?st?=conn.prepareStatement("delete?from?trans_info?where?id=?"); ??st.setInt(1,?transInfo.getId()); ??st.execute(); ?} ?public?List<TransInfo>?query(TransInfo?transInfo)?throws?SQLException{ ??List<TransInfo>?list?=new?ArrayList<TransInfo>(); ??Connection?conn?=DB_util.getConnection(); ??PreparedStatement?st?=conn.prepareStatement("select?*?from?trans_info?where?id?=?"); ??st.setInt(1,?transInfo.getId()); ??ResultSet?rs?=st.getResultSet(); ??TransInfo?t?=null; ??while(rs.next()){ ???t.setId(rs.getInt("id")); ???t.setSource_id(rs.getInt("source_id")); ???t.setSource_account(rs.getString("source_account")); ???t.setDesitination_id(rs.getInt("destination_id")); ???t.setDesitination_account(rs.getString("desitination_account")); ???t.setAmount(rs.getDouble("amount")); ???list.add(t); ??} ??return?list; ?} }
謝啦!謝謝謝
舉報
JDBC的深入挖掘,主要介紹在實(shí)際開發(fā)過程中的各種知識
4 回答是類似線程同步嗎?
1 回答MySQL存儲過程的具體實(shí)現(xiàn)在哪里?
2 回答那個Service業(yè)務(wù)層在哪里調(diào)用?。???
1 回答哪里可以下載這三個文件啊?
1 回答大佬求助啊,都完全跟著老師敲了,為什么保存不了???
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-12-09
2016-12-09
謝啦!謝謝謝