📄 oracleaccountdao.java
字号:
package dao;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javabean.Account;
import javabean.Customer;
import javabean.Operator;
/*
* 瀵箃account琛ㄧ殑鎿嶄綔
* 2007-12-15
* @author:xubo
*
*/
public class OracleAccountDAO implements AccountDAO {
private final String GET_AN_ACCOUNT = "select * from taccount where account_id=?";
private final String INSERT_AN_ACCOUNT = "insert into taccount values(?,?,?,?)";
private final String UPDATE_AN_ACCOUNT = "update taccount set account_balance=? where account_id=?";
//update taccount set account_balance=150 where account_id=3;
public Account isExists(Account account){
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Account acc = new Account();
try{
conn = OracleDAOFactory.getConnection();
pstmt = conn.prepareStatement(GET_AN_ACCOUNT);
pstmt.setInt(1, account.getAccountId());
rs = pstmt.executeQuery();
if(rs.next()){
acc.setAccountId(rs.getInt("ACCOUNT_ID"));
acc.setAddress(rs.getString("CONTACT_ADDRESS"));
acc.setBalance(rs.getFloat("ACCOUNT_BALANCE"));
acc.setName(rs.getString("CONTACT_PERSON"));
return acc;
}else{
return null;
}
}catch(SQLException e){
e.printStackTrace();
}finally{
OracleDAOFactory.closeResultSet(rs);
OracleDAOFactory.closeStatement(pstmt);
OracleDAOFactory.closeConnection(conn);
}
return acc;
}
public boolean createAccount(Account account){
Connection conn = null;
PreparedStatement pstmt = null;
boolean tmp = true;
try{
conn = OracleDAOFactory.getConnection();
pstmt = conn.prepareStatement(INSERT_AN_ACCOUNT);
pstmt.setInt(1, account.getAccountId());
pstmt.setString(2, account.getName());
pstmt.setString(3, account.getAddress());
pstmt.setFloat(4, account.getBalance());
int result = pstmt.executeUpdate();
if(result!=1){
tmp = false;
}
}catch(SQLException e){
e.printStackTrace();
tmp = false;
}finally{
OracleDAOFactory.closeStatement(pstmt);
OracleDAOFactory.closeConnection(conn);
}
return tmp;
}
public boolean updateAccount(Account account){
Connection conn = null;
PreparedStatement pstmt = null;
int customerId = 0;
boolean tmp = true;
try{
conn = OracleDAOFactory.getConnection();
pstmt = conn.prepareStatement(UPDATE_AN_ACCOUNT);
pstmt.setFloat(1, account.getBalance());
pstmt.setInt(2, account.getAccountId());
int result = pstmt.executeUpdate();
System.out.println("鏁版嵁搴擄細鍚堝笎鎴愬姛锛
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -