网上书店完整代码Word文档下载推荐.docx
- 文档编号:22974686
- 上传时间:2023-02-06
- 格式:DOCX
- 页数:71
- 大小:28.94KB
网上书店完整代码Word文档下载推荐.docx
《网上书店完整代码Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《网上书店完整代码Word文档下载推荐.docx(71页珍藏版)》请在冰豆网上搜索。
publicstaticConnectiongetConnection(){
try{
Class.forName(driver);
con=DriverManager.getConnection(url,user,pwd);
System.out.println("
数据库连接成功!
"
);
}catch(ClassNotFoundExceptione){
驱动加载失败!
}catch(SQLExceptione){
数据库连接失败!
}
returncon;
}
publicstaticvoidmain(String[]args){
Connect.getConnection();
}
package.shoeShop.action;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JPanel;
import.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();
package.shoeShop.dao;
importjava.sql.ResultSet;
importjava.sql.Statement;
import.shoeShop.db.Connect;
import.shoeShop.entity.Buyer;
import.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;
import.shoeShop.entity.Goods;
import.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();
//System.out.println(dao.getOneGoods
(1));
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 网上 书店 完整 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)