?? custdao.java
字號:
package com.tingsun.oa.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.tingsun.oa.po.CustInfo;
public class CustDAO extends CommDAO {
public boolean addCustInfo(CustInfo custInfo) {
Connection conn = this.getConn();
PreparedStatement pst = null;
String sql = "INSERT INTO cust_info(ID,custname,isshare,custcode)" +
" VALUES(SEQ_CUST_INFO.nextval,?,?,?)";
// String sql = "INSERT INTO cust_info(ID,custname,isshare,custcode)" +
// " VALUES(SEQ_CUST_INFO.nextval,'"+custInfo.getCustName()+"',?,?)";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, custInfo.getCustName());
pst.setInt(2, custInfo.getShare());
pst.setString(3, custInfo.getCustomerCode());
pst.executeUpdate();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}finally{
this.closeConn(conn, pst);
}
}
public boolean deleteCustInfo(String id) {
Connection conn = this.getConn();
PreparedStatement pst = null;
String sql = "delete from cust_info where id=?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, id);
pst.executeUpdate();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}finally{
this.closeConn(conn, pst);
}
}
public List getCustList() {
Connection conn = this.getConn();
List list = new ArrayList();
PreparedStatement pst = null;
ResultSet rs = null;
String sql = "select ID,custname,isshare,custcode from cust_info";
try {
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
int id = rs.getInt("ID");
String custName = rs.getString("custname");
int isshare = rs.getInt("isshare");
String customerCode = rs.getString("custcode");
CustInfo custInfo = new CustInfo();
custInfo.setCustName(custName);
custInfo.setCustomerCode(customerCode);
custInfo.setId(id);
custInfo.setShare(isshare);
list.add(custInfo);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeConn(conn, pst,rs);
}
return list;
}
public CustInfo getCustInfo(String id) {
Connection conn = this.getConn();
CustInfo custInfo = new CustInfo();
PreparedStatement pst = null;
ResultSet rs = null;
String sql = "select ID,custname,isshare,custcode from cust_info where id=?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, id);
rs = pst.executeQuery();
if(rs.next()){
String custName = rs.getString("custname");
int isshare = rs.getInt("isshare");
String customerCode = rs.getString("custcode");
custInfo.setCustName(custName);
custInfo.setCustomerCode(customerCode);
custInfo.setId(Integer.parseInt(id));
custInfo.setShare(isshare);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeConn(conn, pst,rs);
}
return custInfo;
}
public boolean updateCustInfo(CustInfo custInfo) {
Connection conn = this.getConn();
PreparedStatement pst = null;
String sql = "update cust_info set custname=?,isshare=?,custcode=? where id=?" ;
// String sql = "INSERT INTO cust_info(ID,custname,isshare,custcode)" +
// " VALUES(SEQ_CUST_INFO.nextval,'"+custInfo.getCustName()+"',?,?)";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, custInfo.getCustName());
pst.setInt(2, custInfo.getShare());
pst.setString(3, custInfo.getCustomerCode());
pst.setInt(4, custInfo.getId());
pst.executeUpdate();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}finally{
this.closeConn(conn, pst);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -