package top.tobing.dao;
import top.tobing.domain.Good;
import top.tobing.utils.GoodMapper;
import top.tobing.utils.JDBCUtils;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class GoodDao {
/**
* 根据姓名查询商品
* @param name
* @return
* @throws Exception
*/
public List<Good> findByName(String name) {
Connection connection = null;
ResultSet resultSet =null;
Statement statement = null;
List<Good> list =null;
try {
connection = JDBCUtils.getConnection();
statement = connection.createStatement();
String sql = "select * from good where goodname = '" + name + "'";
resultSet = statement.executeQuery(sql);
list = new ArrayList<>();
while (resultSet.next()) {
Good good = GoodMapper.getObject(resultSet);
list.add(good);
}
}catch (Exception e){
e.printStackTrace();
}
return list;
}
/**
* 根据品牌查询
* @param brand
* @return
*/
public List<Good> findByBrand(String brand) {
Connection connection = null;
ResultSet resultSet =null;
Statement statement = null;
List<Good> list =null;
try {
connection = JDBCUtils.getConnection();
statement = connection.createStatement();
String sql = "select * from good where goodbrand = '" + brand + "'";
resultSet = statement.executeQuery(sql);
list = new ArrayList<>();
while (resultSet.next()) {
Good good = GoodMapper.getObject(resultSet);
list.add(good);
}
}catch (Exception e){
e.printStackTrace();
}
return list;
}
/**
* 根据经办人查询
* @param agent
* @return
*/
public List<Good> findByAgent(String agent) {
Connection connection = null;
ResultSet resultSet =null;
Statement statement = null;
List<Good> list =null;
try {
connection = JDBCUtils.getConnection();
statement = connection.createStatement();
String sql = "select * from good where agent = '" + agent + "'";
resultSet = statement.executeQuery(sql);
list = new ArrayList<>();
while (resultSet.next()) {
Good good = GoodMapper.getObject(resultSet);
list.add(good);
}
}catch (Exception e){
e.printStackTrace();
}
return list;
}
/**
* 添加新商品
* @param good
*/
public void addNewGoods(Good good){
Connection connection = null;
ResultSet resultSet =null;
Statement statement = null;
List<Good> list =null;
try {
connection = JDBCUtils.getConnection();
statement = connection.createStatement();
String sql = "insert into good(goodname,goodbrand,intime,inprice,stock,agent) " +
"values('"+good.getGoodname()+"','"+good.getGoodbrand()+"','"+
new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()) +
"','"+good.getInprice()+"','"+good.getStock()+"','"+good.getAgent()+"')" ;
statement.execute(sql);
}catch (Exception e){
e.printStackTrace();
}
}
/**
* 更新已经存在的商品数量
* @param name
* @param num
*/
public void updateByName(String name,int num) {
Connection connection = null;
ResultSet resultSet =null;
Statement statement = null;
List<Good> list =null;
try {
connection = JDBCUtils.getConnection();
statement = connection.createStatement();
String sql = "update good set stock = "+num+" where goodname ='"+name+"'";
System.out.println(sql);
statement.execute(sql);
}catch (Exception e){
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java+MySQL实现简略的超市信息管理系统.zip (27个子文件)
java-demo-goodadminsystem-master
sql
goodadminsystem.sql 2KB
src
top
tobing
utils
JDBCUtils.java 1KB
GoodMapper.java 1KB
dao
UserDao.java 1KB
GoodDao.java 4KB
view
SaleMenu.java 2KB
Menu.java 3KB
AdminMenu.java 2KB
Login.java 1KB
test
GoodsAdminSystem.java 177B
ConnTest.java 509B
domain
Good.java 2KB
User.java 1KB
out
production
GoodsAdminSystem
top
tobing
utils
JDBCUtils.class 2KB
GoodMapper.class 2KB
dao
UserDao.class 2KB
GoodDao.class 4KB
view
AdminMenu.class 3KB
Menu.class 3KB
Login.class 2KB
SaleMenu.class 3KB
test
GoodsAdminSystem.class 511B
ConnTest.class 1KB
domain
User.class 2KB
Good.class 3KB
libs
mysql-connector-java-8.0.17.jar 2.21MB
GoodsAdminSystem.iml 855B
共 27 条
- 1
资源评论
博士僧小星
- 粉丝: 1924
- 资源: 5885
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功