package com.accp.shop.dao;
import com.accp.shop.pojo.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import com.accp.shop.connection.*;
import com.accp.shop.pojo.CargoListPojo;
/**
* @author 刑鹏飞
*
*/
public class CargoListDAO {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
/**
* 获得所有商品的信息
* @return
*/
public List getCargoList() {
String sql = "Select cargo.Cargo_ID, cargo.Cargo_Name, cargo.Cargo_Type, sell.Sell_Num, sell.Sell_Price From cargo, sell Where cargo.Cargo_ID = sell.Cargo_ID";
ArrayList array = new ArrayList();
try {
conn = Connect.getConnection();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
CargoListPojo CPojo = new CargoListPojo();
CPojo.setCargo_id(rs.getString(1));
CPojo.setCargo_name(rs.getString(2));
CPojo.setCargo_type(rs.getString(3));
CPojo.setSell_num(rs.getInt(4));
CPojo.setSell_price(rs.getDouble(5));
array.add(CPojo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return array;
}
/**
* 返回编辑商品信息
* @param id
* @return
*/
public ArrayList eidtCargoInf(String id) {
String sql = "Select cargo.Cargo_ID, cargo.Cargo_Name, cargo.Cargo_Type, sell.Sell_Num, sell.Sell_Price From cargo, sell Where cargo.Cargo_ID = sell.Cargo_ID and cargo.Cargo_ID=?";
ArrayList list = new ArrayList();
try {
conn = Connect.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
rs = pstmt.executeQuery();
while (rs.next()) {
CargoListPojo CPojo = new CargoListPojo();
CPojo.setCargo_id(rs.getString(1));
CPojo.setCargo_name(rs.getString(2));
CPojo.setCargo_type(rs.getString(3));
CPojo.setSell_num(rs.getInt(4));
CPojo.setSell_price(rs.getDouble(5));
list.add(CPojo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return list;
}
/**
* 在数据库中更新数据
* @param id
* @param name
* @param type
* @param num
* @param price
*/
public void updateCargoInf(String id, String name, String type, int num,
double price) {
String updateCargo = "update cargo set Cargo_Name=?,Cargo_Type=? where Cargo_ID=? ";
String updateSell = "update sell set Sell_Num=?,Sell_Price=? where Cargo_ID=?";
try {
conn = Connect.getConnection();
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(updateCargo);
pstmt.setString(1, name);
pstmt.setString(2, type);
pstmt.setString(3, id);
pstmt.executeUpdate();
pstmt = conn.prepareStatement(updateSell);
pstmt.setInt(1, num);
pstmt.setDouble(2, price);
pstmt.setString(3, id);
pstmt.executeUpdate();
conn.commit();
} catch (Exception e) {
try {
conn.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/**
* 删除商品信息
* @param id
*/
public void deleteInf(String id) {
String delSell = "delete from sell where Cargo_ID=?";
try {
conn = Connect.getConnection();
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(delSell);
pstmt.setString(1, id);
pstmt.executeUpdate();
conn.commit();
} catch (Exception e) {
try {
conn.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/**
* 模糊查询
* @param inf
* @return
*/
public ArrayList blurSearch(String inf) {
String sql = "Select cargo.Cargo_ID, cargo.Cargo_Name, cargo.Cargo_Type, sell.Sell_Num, sell.Sell_Price From cargo, sell Where cargo.Cargo_ID = sell.Cargo_ID and (cargo.Cargo_ID like ? or cargo.Cargo_Name like ? or cargo.Cargo_Type like ? or sell.Sell_Num like ? or sell.Sell_Price like ?)";
ArrayList arry = new ArrayList();
try {
conn = Connect.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "%" + inf + "%");
pstmt.setString(2, "%" + inf + "%");
pstmt.setString(3, "%" + inf + "%");
pstmt.setString(4, "%" + inf + "%");
pstmt.setString(5, "%" + inf + "%");
rs = pstmt.executeQuery();
while (rs.next()) {
CargoListPojo cargoInf = new CargoListPojo();
cargoInf.setCargo_id(rs.getString(1));
cargoInf.setCargo_name(rs.getString(2));
cargoInf.setCargo_type(rs.getString(3));
cargoInf.setSell_num(rs.getInt(4));
cargoInf.setSell_price(rs.getDouble(5));
arry.add(cargoInf);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return arry;
}
/**
* 精确查询
* @param type
* @param inf
* @return
*/
public ArrayList rigourSearch(String type, String inf) {
String sql = "Select cargo.Cargo_ID, cargo.Cargo_Name, cargo.Cargo_Type, sell.Sell_Num, sell.Sell_Price From cargo, sell Where cargo.Cargo_ID = sell.Cargo_ID and "
+ type + "=" + "'" + inf + "'";
ArrayList array = new ArrayList();
try {
conn = Connect.getConnection();
pstmt = conn.prepareStatement(sql);
// pstmt.setString(1, inf);
rs = pstmt.executeQuery();
while (rs.next()) {
CargoListPojo cargo = new CargoListPojo();
cargo.setCargo_id(rs.getString(1));
cargo.setCargo_name(rs.getString(2));
cargo.setCargo_type(rs.getString(3));
cargo.setSell_num(rs.getInt(4));
cargo.setSell_price(rs.getDouble(5));
array.add(cargo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLExceptio
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于jsp servlet的超市管理系统 (173个子文件)
CargoListDAO.class 9KB
StorageDAO.class 8KB
providerDAO.class 8KB
EmpDAO.class 7KB
StockDAO.class 7KB
ManaDAO.class 7KB
modify.class 3KB
newProvider.class 3KB
update.class 3KB
Stock.class 3KB
CheckServlet.class 3KB
SearchInf.class 3KB
manaUpdate.class 3KB
proTypeView.class 2KB
DeleCheck.class 2KB
login.class 2KB
deleteMana.class 2KB
newMana.class 2KB
editMana.class 2KB
AddServlet.class 2KB
editPro.class 2KB
deletePro.class 2KB
CharsetFilter.class 2KB
AddOnSell.class 2KB
AddSell_new.class 2KB
AddSell_Num.class 2KB
selectPro.class 2KB
FinishCargoInf.class 2KB
proLogin.class 2KB
StockPojo.class 2KB
manaView.class 2KB
Manager.class 2KB
FindServlet.class 2KB
Employee.class 2KB
proType.class 2KB
deleteProType.class 2KB
Connect.class 2KB
EidtCargo.class 2KB
EmployeeServlet.class 2KB
CargoListConf.class 2KB
StorageList.class 2KB
CargoType.class 2KB
DeleteCargo.class 2KB
StockList.class 2KB
provider.class 1KB
CargoListPojo.class 1KB
IDExistPojo.class 1KB
StoragePojo.class 1KB
.classpath 1KB
org.eclipse.wst.common.component 471B
org.eclipse.wst.jsdt.ui.superType.container 49B
Menu.css 612B
Thumbs.db 16KB
all.gif 3KB
up.gif 1KB
up1.gif 1KB
down1.gif 1KB
down.gif 1KB
dow.gif 1KB
top.gif 1KB
file.gif 1KB
ico.gif 1KB
bg.gif 202B
font.gif 107B
panel.gif 84B
Menu.html 6KB
frame.html 698B
top.html 422B
main.html 310B
xalan.jar 1.21MB
xercesImpl.jar 1.15MB
standard.jar 503KB
mysql-connector-java-3.2.0-alpha-bin.jar 394KB
mail.jar 298KB
jaxen-full.jar 187KB
jaxp-api.jar 26KB
dom.jar 26KB
sax.jar 26KB
saxpath.jar 23KB
jstl.jar 21KB
jdbc2_0-stdext.jar 7KB
CargoListDAO.java 8KB
EmpDAO.java 8KB
StorageDAO.java 7KB
providerDAO.java 7KB
StockDAO.java 6KB
ManaDAO.java 6KB
newProvider.java 4KB
update.java 4KB
proTypeView.java 3KB
Stock.java 3KB
manaUpdate.java 3KB
deletePro.java 3KB
modify.java 3KB
login.java 3KB
AddSell_Num.java 3KB
CheckServlet.java 3KB
SearchInf.java 3KB
AddSell_new.java 3KB
editPro.java 3KB
共 173 条
- 1
- 2
资源评论
- qq_377490552018-06-18希望有用!!!
- 慢时光丶茶会2018-03-22内容有用,还可以
QQUCHAO
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于keras+fasterRCNN,在VOC格式的口罩数据集上训练,检测人群中有无戴口罩python源码+模型
- 基于opencv+qt5机器视觉的传统缺陷检测, 即采用标准图片和待测图片进行pixel to pixel的XOR操作源码+文档
- 管道内检测缺陷数据库管理系统源码+文档说明+sln
- 毕业设计-低功耗STM32F411开发板(原理图+PCB源文件+官方例程+驱动等)源码+文档说明+截图
- 基于yolov5-tensorRT检测+发动机缸体内壁缺陷检测系统源码+文档说明
- 基于C++实现的锂电池缺陷检测源码+文档说明
- push_version
- 软件自制图像批量压缩工具
- 经典缺陷检测算法源码整理包含PaDiM(2020ICPR)、PatchCore(2022CVPR)、SimpleNet+文档说明
- 基于深度学习的抗梯度噪声的缺陷检测器python源码+文档说明+模型的预训练
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功