添加了注释信息impl v1.0

pull/2/head
cwfeng 9 months ago
parent e95c524ffd
commit 3b4f339f5a

@ -1,5 +1,9 @@
package com.lingnan.supermarket.dao.impl;
import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dto.SupplierInf;
import com.lingnan.supermarket.utils.JDBCUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -8,211 +12,255 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dto.ProdCatalog;
import com.lingnan.supermarket.dto.SupplierInf;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.utils.JDBCUtil;
/**
*
* @cwf 2210461197 2024/12/1
*/
// 实现供应商信息服务接口的类
public class SupplierInfImpl implements SupplierInfService{
// 查询所有供应商信息的方法
@Override
// 该方法用于查找所有未被标记为删除的供应商信息,返回一个供应商信息的向量
// 此方法连接数据库,执行查询,并将结果封装为供应商信息对象的向量
public Vector<SupplierInf> findAllSupplierInf() {
Vector<SupplierInf> supplierInfs = new Vector<SupplierInf>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet=null;
String SQL = "select * from supplierInf where delmark = 1";
Vector<SupplierInf> supplierInfs = new Vector<SupplierInf>(); // 创建一个向量用于存储供应商信息
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet=null; // 初始化结果集对象
String SQL = "select * from supplierInf where delmark = 1"; // SQL查询语句选择未被标记为删除的供应商信息
try {
preparedStatement = conn.prepareStatement(SQL);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
SupplierInf supplierInf = new SupplierInf();
supplierInf.setId(resultSet.getInt("id"));
supplierInf.setName(resultSet.getString("name"));
supplierInf.setContact(resultSet.getString("contact"));
supplierInf.setEmail(resultSet.getString("email"));
supplierInf.setAddress(resultSet.getString("address"));
supplierInf.setDelmark(resultSet.getInt("delmark"));
supplierInfs.add(supplierInf);
preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句
resultSet = preparedStatement.executeQuery(); // 执行查询
while(resultSet.next()) { // 遍历结果集
SupplierInf supplierInf = new SupplierInf(); // 创建一个新的供应商信息对象
supplierInf.setId(resultSet.getInt("id")); // 设置供应商ID
supplierInf.setName(resultSet.getString("name")); // 设置供应商名称
supplierInf.setContact(resultSet.getString("contact")); // 设置供应商联系人
supplierInf.setEmail(resultSet.getString("email")); // 设置供应商邮箱
supplierInf.setAddress(resultSet.getString("address")); // 设置供应商地址
supplierInf.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
supplierInfs.add(supplierInf); // 将供应商信息对象添加到向量中
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
// 关闭数据库连接和相关资源
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return supplierInfs;
return supplierInfs; // 返回存储所有供应商信息的向量
}
// 根据供应商名称查询供应商信息的方法
@Override
// 定义一个查找供应商信息的方法,根据传入的供应商对象进行查询
/**
*
* @param supplierInf
* @return
*/
public Vector<SupplierInf> findByNameSupplierInf(SupplierInf supplierInf) {
//SupplierInf supplierInf = new SupplierInf();
Connection conn = JDBCUtil.getConn();
Vector<SupplierInf> v = new Vector<>();
System.out.println(supplierInf.getName());
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
Vector<SupplierInf> v = new Vector<>(); // 创建一个向量用于存储供应商信息
System.out.println(supplierInf.getName()); // 打印供应商名称
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet = null; // 初始化结果集对象
try {
if(!supplierInf.getName().equals("")){
String s='%'+supplierInf.getName()+'%';
preparedStatement = conn.prepareStatement("select * from supplierInf where name like ? and delmark = 1");
preparedStatement.setString(1, s);
if(!supplierInf.getName().equals("")){ // 如果供应商名称不为空
String s='%'+supplierInf.getName()+'%'; // 构建模糊查询字符串
preparedStatement = conn.prepareStatement("select * from supplierInf where name like ? and delmark = 1"); // 准备SQL查询语句
preparedStatement.setString(1, s); // 设置查询参数
}else
preparedStatement = conn.prepareStatement("select * from supplierInf where delmark = 1");
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
supplierInf = new SupplierInf();
supplierInf.setId(resultSet.getInt("id"));
supplierInf.setName(resultSet.getString("name"));
supplierInf.setAddress(resultSet.getString("address"));
supplierInf.setContact(resultSet.getString("contact"));
supplierInf.setEmail(resultSet.getString("email"));
supplierInf.setDelmark(1);
v.add(supplierInf);
preparedStatement = conn.prepareStatement("select * from supplierInf where delmark = 1"); // 准备SQL查询语句选择未被标记为删除的供应商信息
resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) { // 遍历结果集
supplierInf = new SupplierInf(); // 创建一个新的供应商信息对象
supplierInf.setId(resultSet.getInt("id")); // 设置供应商ID
supplierInf.setName(resultSet.getString("name")); // 设置供应商名称
supplierInf.setAddress(resultSet.getString("address")); // 设置供应商地址
supplierInf.setContact(resultSet.getString("contact")); // 设置供应商联系人
supplierInf.setEmail(resultSet.getString("email")); // 设置供应商邮箱
supplierInf.setDelmark(1); // 设置删除标记
v.add(supplierInf); // 将供应商信息对象添加到向量中
}
Iterator<SupplierInf> it=v.iterator(); // 获取向量的迭代器
while(it.hasNext()){ // 遍历向量
supplierInf=it.next(); // 获取下一个供应商信息对象
System.out.println(supplierInf.getId()+" "+supplierInf.getName()+" "+supplierInf.getAddress()+" "+supplierInf.getContact()+" "+supplierInf.getEmail()+" "+supplierInf.getDelmark()+" "); // 打印供应商信息
}
Iterator<SupplierInf> it=v.iterator();
while(it.hasNext()){
supplierInf=it.next();
System.out.println(supplierInf.getId()+" "+supplierInf.getName()+" "+supplierInf.getAddress()+" "+supplierInf.getContact()+" "+supplierInf.getEmail()+" "+supplierInf.getDelmark()+" ");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return v;
return v; // 返回存储供应商信息的向量
}
// 添加供应商信息的方法
/**
*
*
* @param supplierInf
* @return 10
*/
@Override
public int addSupplierInf(SupplierInf supplierInf) {
int flag = 0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag = 0; // 初始化标志为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement
("insert into supplierInf values (null,?,?,?,?,?)");
("insert into supplierInf values (null,?,?,?,?,?)"); // 准备SQL插入语句
//preparedStatement.setInt(1, supplierInf.getId());
preparedStatement.setString(1, supplierInf.getName());
preparedStatement.setString(2, supplierInf.getAddress());
preparedStatement.setString(3, supplierInf.getContact());
preparedStatement.setString(4, supplierInf.getEmail());
preparedStatement.setInt(5, 1);
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
preparedStatement.setString(1, supplierInf.getName()); // 设置供应商名称
preparedStatement.setString(2, supplierInf.getAddress()); // 设置供应商地址
preparedStatement.setString(3, supplierInf.getContact()); // 设置供应商联系人
preparedStatement.setString(4, supplierInf.getEmail()); // 设置供应商邮箱
preparedStatement.setInt(5, 1); // 设置删除标记
preparedStatement.executeUpdate(); // 执行插入操作
flag = 1; // 设置标志为1表示插入成功
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
}
return flag; // 返回插入结果标志
}
// 删除供应商信息的方法
/**
* ID
*
* @param id ID
* @return 10
*/
@Override
public int deleteSupplierInf(int id) {
int flag = 0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag = 0; // 初始化标志为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement
("delete from supplierInf where id = ?");
preparedStatement.setInt(1, id);
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
("delete from supplierInf where id = ?"); // 准备SQL删除语句
preparedStatement.setInt(1, id); // 设置供应商ID
preparedStatement.executeUpdate(); // 执行删除操作
flag = 1; // 设置标志为1表示删除成功
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回删除结果标志
}
// 更新供应商信息的方法
/**
*
*
* @param supplierInf
* @return 10
*/
@Override
public int updateSupplierInf(SupplierInf supplierInf) {
int flag=0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag=0; // 初始化标志为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement("update supplierInf set name=?,address=?,contact=?,email=?,delmark=? where id = ?");
preparedStatement.setString(1,supplierInf.getName());
preparedStatement.setString(2,supplierInf.getAddress());
preparedStatement.setString(3,supplierInf.getContact());
preparedStatement.setString(4, supplierInf.getEmail());
preparedStatement.setInt(5, supplierInf.getDelmark());
preparedStatement.setInt(6,supplierInf.getId());
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null, preparedStatement, conn);
preparedStatement = conn.prepareStatement("update supplierInf set name=?,address=?,contact=?,email=?,delmark=? where id = ?"); // 准备SQL更新语句
preparedStatement.setString(1,supplierInf.getName()); // 设置供应商名称
preparedStatement.setString(2,supplierInf.getAddress()); // 设置供应商地址
preparedStatement.setString(3,supplierInf.getContact()); // 设置供应商联系人
preparedStatement.setString(4, supplierInf.getEmail()); // 设置供应商邮箱
preparedStatement.setInt(5, supplierInf.getDelmark()); // 设置删除标记
preparedStatement.setInt(6,supplierInf.getId()); // 设置供应商ID
preparedStatement.executeUpdate(); // 执行更新操作
flag = 1; // 设置标志为1表示更新成功
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回更新结果标志
}
// 获取所有供应商名称的方法
// 该方法从数据库中查询所有供应商的名称,并将其存储在一个列表中返回
@Override
public ArrayList<String> findNameSupplier() {
Connection conn=JDBCUtil.getConn();
ArrayList<String> v = new ArrayList<String>();
SupplierInf supplierInf;
PreparedStatement pstmt = null;
ResultSet resultSet=null;
v.add("全部");
Connection conn=JDBCUtil.getConn(); // 获取数据库连接
ArrayList<String> v = new ArrayList<String>(); // 创建一个列表用于存储供应商名称
SupplierInf supplierInf; // 声明一个供应商信息对象
PreparedStatement pstmt = null; // 初始化预编译语句对象
ResultSet resultSet=null; // 初始化结果集对象
v.add("全部"); // 添加默认选项“全部”
try {
pstmt = conn.prepareStatement("select * from supplierInf");
resultSet = pstmt.executeQuery();
while(resultSet.next()){
v.add(resultSet.getString("name"));
pstmt = conn.prepareStatement("select * from supplierInf"); // 准备SQL查询语句
resultSet = pstmt.executeQuery(); // 执行查询
while(resultSet.next()){ // 遍历结果集
v.add(resultSet.getString("name")); // 将供应商名称添加到列表中
}
} catch (SQLException e) {
} catch (SQLException e) { // 捕获SQL异常
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
JDBCUtil.close(resultSet, pstmt, conn);
e.printStackTrace(); // 打印异常堆栈信息
}finally{ // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接
}
return v;
return v; // 返回存储供应商名称的列表
}
// 根据供应商名称查找其ID的方法
/**
* ID
* ID0
* -1
*
* @param name
* @return ID
*/
@Override
public int findIdSupplierByName(String name) {
int flag = -1;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet= null;
int id=0;
int flag = -1; // 初始化标志为-1
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet= null; // 初始化结果集对象
int id=0; // 初始化供应商ID为0
try {
if(name.equals("全部"))
return id;
if(name.equals("全部")) // 如果供应商名称为“全部”
return id; // 返回默认ID
preparedStatement = conn.prepareStatement
("select * from supplierInf where name=?");
preparedStatement.setString(1, name);
resultSet=preparedStatement.executeQuery();
if(resultSet.next()){
return resultSet.getInt("id");
("select * from supplierInf where name=?"); // 准备SQL查询语句
preparedStatement.setString(1, name); // 设置查询参数
resultSet=preparedStatement.executeQuery(); // 执行查询
if(resultSet.next()){ // 如果找到对应记录
return resultSet.getInt("id"); // 返回供应商ID
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回查询结果标志
}
}
}

@ -1,152 +1,174 @@
package com.lingnan.supermarket.dao.impl;
import com.lingnan.supermarket.dao.inRecordService;
import com.lingnan.supermarket.dto.InRecord;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.utils.JDBCUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Vector;
import com.lingnan.supermarket.dao.inRecordService;
import com.lingnan.supermarket.dto.InOrder;
import com.lingnan.supermarket.dto.InRecord;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.utils.JDBCUtil;
/**
*
* @cwf2210461197 2024/12/2
* @version 1.0
*/
public class inRecordServiceImpl implements inRecordService{
/**
*
* @return
*/
@Override
public Vector<InRecord> findAllinRecord() {
Vector<InRecord> inRecords = new Vector<InRecord>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet=null;
String SQL = "select * from inRecord";
Vector<InRecord> inRecords = new Vector<InRecord>(); // 创建一个向量用于存储进货记录
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet=null; // 初始化结果集对象
String SQL = "select * from inRecord"; // SQL查询语句选择所有进货记录
try {
preparedStatement = conn.prepareStatement(SQL);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
InRecord inRecord = new InRecord();
inRecord.setiNumber(resultSet.getString("iNumber"));
inRecord.setSum(resultSet.getInt("sum"));
inRecord.setInPrice(resultSet.getFloat("inPrice"));
inRecords.add(inRecord);
preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句
resultSet = preparedStatement.executeQuery(); // 执行查询
while(resultSet.next()) { // 遍历结果集
InRecord inRecord = new InRecord(); // 创建一个新的进货记录对象
inRecord.setiNumber(resultSet.getString("iNumber")); // 设置进货单号
inRecord.setSum(resultSet.getInt("sum")); // 设置进货数量
inRecord.setInPrice(resultSet.getFloat("inPrice")); // 设置进货价格
inRecords.add(inRecord); // 将进货记录对象添加到向量中
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return inRecords;
return inRecords; // 返回存储所有进货记录的向量
}
@Override
/**
*
*
* @param iNumber
* @return
*/
@Override
public Vector<InRecord> findByIdinRecord(String iNumber) {
InRecord inRecord;
Vector<InRecord> v = new Vector<InRecord>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
InRecord inRecord; // 声明一个进货记录对象
Vector<InRecord> v = new Vector<InRecord>(); // 创建一个向量用于存储进货记录
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet = null; // 初始化结果集对象
try {
preparedStatement = conn.prepareStatement("select * from inRecord where iNumber = ?");
preparedStatement.setString(1, iNumber);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
inRecord = new InRecord();
inRecord.setiNumber(resultSet.getString("iNumber"));
inRecord.setId(resultSet.getString("id"));
inRecord.setSum(resultSet.getInt("sum"));
inRecord.setInPrice(resultSet.getFloat("Price"));
v.add(inRecord);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
preparedStatement = conn.prepareStatement("select * from inRecord where iNumber = ?"); // 准备SQL查询语句
preparedStatement.setString(1, iNumber); // 设置查询参数
resultSet = preparedStatement.executeQuery(); // 执行查询
while(resultSet.next()) { // 遍历结果集
inRecord = new InRecord(); // 创建一个新的进货记录对象
inRecord.setiNumber(resultSet.getString("iNumber")); // 设置进货单号
inRecord.setId(resultSet.getString("id")); // 设置商品ID
inRecord.setSum(resultSet.getInt("sum")); // 设置进货数量
inRecord.setInPrice(resultSet.getFloat("Price")); // 设置进货价格
v.add(inRecord); // 将进货记录对象添加到向量中
}
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return v;
return v; // 返回存储进货记录的向量
}
@Override
public int addinRecord(InRecord ir) {
int flag = 0;
String iNumber = ir.getiNumber();
int sum = ir.getSum();
Float inPrice = ir.getInPrice();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
// 该方法用于将进货记录添加到数据库中。
// 参数 ir 是一个包含进货信息的对象。
// 返回值 flag 表示插入的结果1表示成功-1表示失败。
public int addinRecord(InRecord ir) {
int flag = 0; // 初始化标志为0
String iNumber = ir.getiNumber(); // 获取进货单号
int sum = ir.getSum(); // 获取进货数量
Float inPrice = ir.getInPrice(); // 获取进货价格
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement
("insert into inRecord values (?,?,?)");
preparedStatement.setString(1, iNumber);
preparedStatement.setInt(2, sum);
preparedStatement.setFloat(3, inPrice);
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
flag = -1;
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
("insert into inRecord values (?,?,?)"); // 准备SQL插入语句
preparedStatement.setString(1, iNumber); // 设置进货单号
preparedStatement.setInt(2, sum); // 设置进货数量
preparedStatement.setFloat(3, inPrice); // 设置进货价格
preparedStatement.executeUpdate(); // 执行插入操作
flag = 1; // 设置标志为1表示插入成功
} catch (SQLException e) { // 捕获SQL异常
flag = -1; // 设置标志为-1表示插入失败
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回插入结果标志
}
@Override
// 删除进货记录方法,根据进货单号进行删除操作
@Override
public int deleteinRecord(String iNumber) {
int flag = 0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag = 0; // 初始化标志为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement
("delete from inRecord where iNumber = ?");
preparedStatement.setString(1, iNumber);
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
flag = -1;
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
("delete from inRecord where iNumber = ?"); // 准备SQL删除语句
preparedStatement.setString(1, iNumber); // 设置进货单号
preparedStatement.executeUpdate(); // 执行删除操作
flag = 1; // 设置标志为1表示删除成功
} catch (SQLException e) { // 捕获SQL异常
flag = -1; // 设置标志为-1表示删除失败
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回删除结果标志
}
public boolean insertInRecord(String iNumber,Production p) {
boolean flag = false;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
/**
*
*
* @param iNumber
* @param p
* @return truefalse
*/
public boolean insertInRecord(String iNumber,Production p) {
boolean flag = false; // 初始化标志为false
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement("insert into inRecord values(?,?,?,?)");
preparedStatement.setString(1, iNumber);
preparedStatement.setString(2, p.getId());
preparedStatement.setInt(3,p.getSum());
preparedStatement.setFloat(4, p.getPrice());
if(preparedStatement.executeUpdate()==1)
flag = true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
preparedStatement = conn.prepareStatement("insert into inRecord values(?,?,?,?)"); // 准备SQL插入语句
preparedStatement.setString(1, iNumber); // 设置进货单号
preparedStatement.setString(2, p.getId()); // 设置商品ID
preparedStatement.setInt(3,p.getSum()); // 设置进货数量
preparedStatement.setFloat(4, p.getPrice()); // 设置进货价格
if(preparedStatement.executeUpdate()==1) // 执行插入操作
flag = true; // 如果成功执行插入设置标志为true
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回插入结果标志
}
}
}
Loading…
Cancel
Save