📄 vendordao.java
字号:
package com.yiboit.cfss.vendor;
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.yiboit.cfss.db.ManageConnection;
public class VendorDAO {
public boolean updateVendor(VendorBean v) throws SQLException {
boolean result = false;
Connection conn = null;
try {
conn = ManageConnection.getConnection();
String sql = "update shop_vendor set vendor_name = ?" +
", vendor_address = ?, vendor_phone = ?" +
", vendor_fax = ?, vendor_contact_person = ?" +
" where vendor_id = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, v.getVendorName());
pstmt.setString(2, v.getVendorAddress());
pstmt.setString(3, v.getVendorPhone());
pstmt.setString(4, v.getVendorFax());
pstmt.setString(5, v.getVendorContactPerson());
pstmt.setInt(6, v.getVendorId());
result = pstmt.executeUpdate() == 1 ? true : false;
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
}
}
}
return result;
}
public boolean addVendor(VendorBean v) throws SQLException {
boolean result = false;
Connection conn = null;
try {
conn = ManageConnection.getConnection();
String sql = "insert into shop_vendor(vendor_id"
+ ", vendor_name, vendor_address, vendor_phone"
+ ", vendor_fax, vendor_contact_person)"
+ " values(SEQ_VENDOR_ID.nextval, ?, ?, ?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, v.getVendorName());
pstmt.setString(2, v.getVendorAddress());
pstmt.setString(3, v.getVendorPhone());
pstmt.setString(4, v.getVendorFax());
pstmt.setString(5, v.getVendorContactPerson());
result = pstmt.executeUpdate() == 1 ? true : false;
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
}
}
}
return result;
}
public List getVendorList() throws SQLException {
List<VendorBean> result = null;
Connection conn = null;
try {
conn = ManageConnection.getConnection();
PreparedStatement pstmt = conn
.prepareStatement("select * from shop_vendor");
ResultSet rs = pstmt.executeQuery();
if (rs != null) {
result = new ArrayList<VendorBean>();
while (rs.next()) {
result.add(new VendorBean(rs.getInt("vendor_id"), rs
.getString("vendor_name"), rs
.getString("vendor_address"), rs
.getString("vendor_phone"), rs
.getString("vendor_fax"), rs
.getString("vendor_contact_person")));
}
}
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
}
}
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -