网上书店完整代码Word格式.docx
《网上书店完整代码Word格式.docx》由会员分享,可在线阅读,更多相关《网上书店完整代码Word格式.docx(61页珍藏版)》请在冰点文库上搜索。
publicstaticConnectiongetConnection(){
try{
Class.forName(driver);
con=DriverManager.getConnection(url,user,pwd);
System.out.println("
数据库连接成功!
"
);
}catch(ClassNotFoundExceptione){
驱动加载失败!
}catch(SQLExceptione){
数据库连接失败!
}
returncon;
}
publicstaticvoidmain(String[]args){
Connect.getConnection();
}
packagecom.shoeShop.action;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JPanel;
importcom.shoeShop.view.RegisterFrame;
publicclassdocMenuActionimplementsActionListener{
RegisterFrameregister=null;
JPanelcusPanel=null;
JPaneldocPanel=null;
publicdocMenuAction(RegisterFrameregister){
this.register=register;
this.cusPanel=register.cusPanel;
this.docPanel=register.docPanel;
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
register.flag=1;
//System.out.println(register.flag);
register.remove(cusPanel);
register.add(docPanel);
docPanel.updateUI();
packagecom.shoeShop.dao;
importjava.sql.ResultSet;
importjava.sql.Statement;
importcom.shoeShop.db.Connect;
importcom.shoeShop.entity.Buyer;
importcom.shoeShop.entity.Seller;
publicclassBuyerDao{
privatestaticConnectionconn;
privatestaticStatementstatement;
privatestaticResultSetresultSet;
//插入数据,用于注册
publicintinsertBuyer(Buyerbuyer){
intflag=0;
conn=Connect.getConnection();
statement=conn.createStatement();
Stringsql="
insertintobuyervalues('
+buyer.getId()+"
'
'
+buyer.getName()+"
+buyer.getPwd()+"
+buyer.getAddress()+"
)"
//System.out.println("
buyer"
+sql);
flag=statement.executeUpdate(sql);
statement.close();
conn.close();
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
//System.out.println(flag);
returnflag;
//通过用户名和密码查询,用于登录
publicstaticBuyergetBuyer(Stringname,Stringpwd){
Buyerbuyer=newBuyer();
select*frombuyerwherebuyer_id='
+name+"
andpwd='
+pwd+"
resultSet=statement.executeQuery(sql);
while(resultSet.next()){
buyer.setId(resultSet.getString("
buyer_id"
));
buyer.setName(resultSet.getString("
buyer_name"
buyer.setPwd(resultSet.getString("
pwd"
buyer.setAddress(resultSet.getString("
address"
}
resultSet.close();
returnbuyer;
BuyerDaodao=newBuyerDao();
System.out.println(dao.getBuyer("
zxk"
"
654321"
//Buyerbuyer=newBuyer();
//buyer.setId("
lily"
//buyer.setName("
长理专卖"
//buyer.setPwd("
123456"
//buyer.setAddress("
湖南长沙"
//dao.insertBuyer(buyer);
importjava.util.ArrayList;
importcom.shoeShop.entity.Goods;
importcom.shoeShop.imp.User;
publicclassGoodsDao{
//查询登录商家的所有商品,用于商家管理自己的商品
publicArrayListgetAllGoods(){
ArrayListlist=newArrayList();
select*fromgoodsa,sellerbwherea.seller_id=b.seller_idandb.seller_id='
+User.getUserName()+"
Sellerseller=newSeller();
seller.setName(resultSet.getString("
seller_name"
seller.setAddress(resultSet.getString("
Goodsgoods=newGoods();
goods.setSeller(seller);
goods.setId(resultSet.getInt("
goods_id"
goods.setName(resultSet.getString("
goods_name"
goods.setSeller_id(resultSet.getString("
seller_id"
goods.setDiscount(resultSet.getInt("
discount"
goods.setNum(resultSet.getInt("
num"
goods.setPrice(resultSet.getInt("
price"
//System.out.println(goods.toString());
list.add(goods);
}finally{
try{
resultSet.close();
statement.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
returnlist;
//查询所有商家的所有商品.用于用户搜索商品
publicArrayListgetAllSellerGoods(){
select*fromgoodsa,sellerbwherea.seller_id=b.seller_id"
//根据商品号查询商品信息
publicGoodsgetOneGoods(intid){
Goodsgoods=newGoods();
select*fromgoodswheregoods_id="
+id;
goods.setId(id);
returngoods;
//修改商品信息
publicintupdateGoods(Goodsgoods){
updategoodssetgoods_name='
+goods.getName()+"
price="
+goods.getPrice()
+"
discount="
+goods.getDiscount()+"
num="
+goods.getNum()+"
wheregoods_id="
+goods.getId();
//通过id删除商品
publicintdeleteById(intid){
deletegoodswheregoods_id="
//添加
publicintinsertGoods(Goodsgoods){
insertintogoodsvalues((selectmax(goods_id+1)fromgoods),'
"
+goods.getPrice()+"
GoodsDaodao=newGoodsDao();
//Goodsgoods=newGoods();
//goods.setName("
c++"
//goods.setPrice(50);
//User.setUserName("
niclascage"
//goods.setDiscount(8);
//goods.setNum(10);
//System.out.println("
main"
ii"
+dao.insertGoods(goods));
//System.out.println(dao.deleteById(4));
//goods.setId
(1);
oracle"
//goods.setNum(5);
//System.out.println(dao.updateGoods(goods));
dao.getAllSellerGoods();
//Syst