?? accountdao.java
字號:
package com.tarena.bank.persist;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.tarena.bank.biz.Account;
public class AccountDAO implements IAccountDAO {
private String t = "t_sd0711_act";
public void insert(Account act) {
Connection con = JdbcUtil.getConnection();
PreparedStatement ps = null;
String sql = "insert into "+
t+" values(?,?)";
try {
ps = con.prepareStatement(sql);
ps.setString(1,act.getActNo());
ps.setDouble(2,act.getBal());
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
JdbcUtil.release(null,ps,con);
}
}
public void delete(String actNo) {
Connection con = JdbcUtil.getConnection();
PreparedStatement ps = null;
String sql = "delete table "+t;
try {
ps = con.prepareStatement(sql);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
JdbcUtil.release(null,ps,con);
}
}
public void update(Account act) {
Connection con = JdbcUtil.getConnection();
PreparedStatement ps = null;
String sql = "update "+
t+" set actNo=?,bal=? " +
"where actNo=?";
try {
ps = con.prepareStatement(sql);
ps.setString(1,act.getActNo());
ps.setDouble(2,act.getBal());
ps.setString(3,act.getActNo());
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
JdbcUtil.release(null,ps,con);
}
}
public Account findByActNo(String actNo) {
Account act = null;
Connection con = JdbcUtil.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select * from "+
t+" where actNo=?";
try {
ps = con.prepareStatement(sql);
ps.setString(1,actNo);
rs = ps.executeQuery();
if(rs.next()){
act = new Account(
rs.getString(1),rs.getDouble(2));
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
JdbcUtil.release(rs,ps,con);
}
return act;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -