缺了两个实体类,两个Dao类不会打啊
求源代码,,谢。我定好好学习
求源代码,,谢。我定好好学习
2016-12-06
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; } }
举报