package com.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.bean.Shop;
import com.comm.DBClass;
public class ShopDao {
/**
* 发布商品方法
*/
public boolean addShop(Shop sp){
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="insert into shop values('"+sp.getSname()+"',"+sp.getSprice()+","+sp.getSnum()+",'"+sp.getStype()+"','"+sp.getStore()+"','"+sp.getSay()+"','"+sp.getSimg()+"','"+sp.getUname()+"')";
sta.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
/**
* 修改商品数量方法
*/
public boolean updNum(int snum,String sname){
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="update shop set snum=snum-"+snum+" where sname='"+sname+"'";
sta.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
/**
* 下架商品方法
*/
public boolean delShop(int sid){
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="delete from shop where sid="+sid+"";
sta.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
/**
* 按类型查询商品方法
*/
public ArrayList<Shop> typeShopQuery(String stype){
ArrayList<Shop> list=new ArrayList<Shop>();
Shop sp=null;
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="select * from shop where stype='"+stype+"'";
ResultSet rs=sta.executeQuery(sql);
while(rs.next()){
sp=new Shop();
sp.setSid(rs.getInt(1));
sp.setSname(rs.getString(2));
sp.setSprice(rs.getDouble(3));
sp.setSnum(rs.getInt(4));
sp.setStype(rs.getString(5));
sp.setStore(rs.getString(6));
sp.setSay(rs.getString(7));
sp.setSimg(rs.getString(8));
sp.setUname(rs.getString(9));
list.add(sp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return list;
}
/**
* 按店铺查询商品方法
*/
public ArrayList<Shop> storeShopQuery(String store){
ArrayList<Shop> list=new ArrayList<Shop>();
Shop sp=null;
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="select * from shop where store='"+store+"'";
ResultSet rs=sta.executeQuery(sql);
while(rs.next()){
sp=new Shop();
sp.setSid(rs.getInt(1));
sp.setSname(rs.getString(2));
sp.setSprice(rs.getDouble(3));
sp.setSnum(rs.getInt(4));
sp.setStype(rs.getString(5));
sp.setStore(rs.getString(6));
sp.setSay(rs.getString(7));
sp.setSimg(rs.getString(8));
sp.setUname(rs.getString(9));
list.add(sp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return list;
}
/**
* 查询所有商品方法
*/
public ArrayList<Shop> ShopQuery(){
ArrayList<Shop> list=new ArrayList<Shop>();
Shop sp=null;
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="select * from shop";
ResultSet rs=sta.executeQuery(sql);
while(rs.next()){
sp=new Shop();
sp.setSid(rs.getInt(1));
sp.setSname(rs.getString(2));
sp.setSprice(rs.getDouble(3));
sp.setSnum(rs.getInt(4));
sp.setStype(rs.getString(5));
sp.setStore(rs.getString(6));
sp.setSay(rs.getString(7));
sp.setSimg(rs.getString(8));
sp.setUname(rs.getString(9));
list.add(sp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return list;
}
/**
* 商品ShopInfo
*/
public ArrayList<Shop> ShopInfo(Shop shop){
ArrayList<Shop> list=new ArrayList<Shop>();
Shop sp=null;
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="select * from shop where sid='"+shop.getSid()+"'";
ResultSet rs=sta.executeQuery(sql);
while(rs.next()){
sp=new Shop();
sp.setSid(rs.getInt(1));
sp.setSname(rs.getString(2));
sp.setSprice(rs.getDouble(3));
sp.setSnum(rs.getInt(4));
sp.setStype(rs.getString(5));
sp.setStore(rs.getString(6));
sp.setSay(rs.getString(7));
sp.setSimg(rs.getString(8));
sp.setUname(rs.getString(9));
list.add(sp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return list;
}
/**
* 按掌柜查询商品方法
*/
public ArrayList<Shop> userShopQuery(String uname){
ArrayList<Shop> list=new ArrayList<Shop>();
Shop sp=null;
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="select * from shop where uname='"+uname+"'";
ResultSet rs=sta.executeQuery(sql);
while(rs.next()){
sp=new Shop();
sp.setSid(rs.getInt(1));
sp.setSname(rs.getString(2));
sp.setSprice(rs.getDouble(3));
sp.setSnum(rs.getInt(4));
sp.setStype(rs.getString(5));
sp.setStore(rs.getString(6));
sp.setSay(rs.getString(7));
sp.setSimg(rs.getString(8));
sp.setUname(rs.getString(9));
list.add(sp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return list;
}
/**
* 按用户名查询商品方法
*/
public ArrayList<Shop> unameShopQuery(String uname){
ArrayList<Shop> list=new ArrayList<Shop>();
Shop sp=null;
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
String sql="select * from shop where uname='"+uname+"'";
ResultSet rs=sta.executeQuery(sql);
while(rs.next()){
sp=new Shop();
sp.setSid(rs.getInt(1));
sp.setSname(rs.getString(2));
sp.setSprice(rs.getDouble(3));
sp.setSnum(rs.getInt(4));
sp.setStype(rs.getString(5));
sp.setStore(rs.getString(6));
sp.setSay(rs.getString(7));
sp.setSimg(rs.getString(8));
sp.setUname(rs.getString(9));
list.add(sp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return list;
}
/**
* 模糊查询商品方法
*/
public ArrayList<Shop> searchShopQuery(String sql){
ArrayList<Shop> list=new ArrayList<Shop>();
Shop sp=null;
Connection conn=DBClass.getData();
try {
Statement sta=conn.createStatement();
ResultSet rs=sta.executeQuery(sql);
while(rs.next()){
sp=new Shop();
sp.setSid(rs.getInt(1));
sp.setSname(rs.getString(2));
sp.setSprice(rs.getDouble(3));
sp.setSnum(rs.getInt(4));
sp.setStype(rs.getString(5));
sp.setStore(rs.getString(6));
sp.setSay(rs.getString(7));
sp.setSimg(rs.getString(8));
sp.setUname(rs.getString(9));
list.add(sp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return list;
}
}
评论1