网上书店完整代码.docx
- 文档编号:8212820
- 上传时间:2023-01-29
- 格式:DOCX
- 页数:61
- 大小:29.56KB
网上书店完整代码.docx
《网上书店完整代码.docx》由会员分享,可在线阅读,更多相关《网上书店完整代码.docx(61页珍藏版)》请在冰豆网上搜索。
网上书店完整代码
附录全部源代码
packagecom.shoeShop.db;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.SQLException;
publicclassConnect{
privatestaticConnectioncon=null;
privatestaticStringurl="jdbc:
oracle:
thin:
@localhost:
1521:
ORCL";
privatestaticStringdriver="oracle.jdbc.driver.OracleDriver";
privatestaticStringuser="scott";
privatestaticStringpwd="tiger";
publicstaticConnectiongetConnection(){
try{
Class.forName(driver);
con=DriverManager.getConnection(url,user,pwd);
System.out.println("数据库连接成功!
");
}catch(ClassNotFoundExceptione){
System.out.println("驱动加载失败!
");;
}catch(SQLExceptione){
System.out.println("数据库连接失败!
");
}
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.Connection;
importjava.sql.ResultSet;
importjava.sql.SQLException;
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();
try{
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();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
//System.out.println(flag);
returnflag;
}
//通过用户名和密码查询,用于登录
publicstaticBuyergetBuyer(Stringname,Stringpwd){
conn=Connect.getConnection();
Buyerbuyer=newBuyer();
try{
statement=conn.createStatement();
Stringsql="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();
statement.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
returnbuyer;
}
publicstaticvoidmain(String[]args){
BuyerDaodao=newBuyerDao();
System.out.println(dao.getBuyer("zxk","654321"));
//Buyerbuyer=newBuyer();
//buyer.setId("lily");
//buyer.setName("长理专卖");
//buyer.setPwd("123456");
//buyer.setAddress("湖南长沙");
//dao.insertBuyer(buyer);
}
}
packagecom.shoeShop.dao;
importjava.sql.Connection;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.util.ArrayList;
importcom.shoeShop.db.Connect;
importcom.shoeShop.entity.Goods;
importcom.shoeShop.entity.Seller;
importcom.shoeShop.imp.User;
publicclassGoodsDao{
privatestaticConnectionconn;
privatestaticStatementstatement;
privatestaticResultSetresultSet;
//查询登录商家的所有商品,用于商家管理自己的商品
publicArrayListgetAllGoods(){
ArrayListlist=newArrayList();
conn=Connect.getConnection();
try{
statement=conn.createStatement();
Stringsql="select*fromgoodsa,sellerbwherea.seller_id=b.seller_idandb.seller_id='"+User.getUserName()+"'";
resultSet=statement.executeQuery(sql);
while(resultSet.next()){
Sellerseller=newSeller();
seller.setName(resultSet.getString("seller_name"));
seller.setAddress(resultSet.getString("address"));
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);
}
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
try{
resultSet.close();
statement.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
returnlist;
}
//查询所有商家的所有商品.用于用户搜索商品
publicArrayListgetAllSellerGoods(){
ArrayListlist=newArrayList();
conn=Connect.getConnection();
try{
statement=conn.createStatement();
Stringsql="select*fromgoodsa,sellerbwherea.seller_id=b.seller_id";
resultSet=statement.executeQuery(sql);
while(resultSet.next()){
Sellerseller=newSeller();
seller.setName(resultSet.getString("seller_name"));
seller.setAddress(resultSet.getString("address"));
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);
}
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
try{
resultSet.close();
statement.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
returnlist;
}
//根据商品号查询商品信息
publicGoodsgetOneGoods(intid){
Goodsgoods=newGoods();
conn=Connect.getConnection();
try{
statement=conn.createStatement();
Stringsql="select*fromgoodswheregoods_id="+id;
resultSet=statement.executeQuery(sql);
while(resultSet.next()){
goods.setId(id);
goods.setName(resultSet.getString("goods_name"));
goods.setPrice(resultSet.getInt("price"));
goods.setNum(resultSet.getInt("num"));
goods.setDiscount(resultSet.getInt("discount"));
goods.setSeller_id(resultSet.getString("seller_id"));
goods.setNum(resultSet.getInt("num"));
}
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
try{
resultSet.close();
statement.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
returngoods;
}
//修改商品信息
publicintupdateGoods(Goodsgoods){
intflag=0;
conn=Connect.getConnection();
try{
statement=conn.createStatement();
Stringsql="updategoodssetgoods_name='"+goods.getName()+"',price="+goods.getPrice()
+",discount="+goods.getDiscount()+",num="+goods.getNum()+"wheregoods_id="+goods.getId();
flag=statement.executeUpdate(sql);
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
try{
statement.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
returnflag;
}
//通过id删除商品
publicintdeleteById(intid){
intflag=0;
conn=Connect.getConnection();
try{
statement=conn.createStatement();
Stringsql="deletegoodswheregoods_id="+id;
flag=statement.executeUpdate(sql);
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
try{
statement.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
returnflag;
}
//添加
publicintinsertGoods(Goodsgoods){
intflag=0;
conn=Connect.getConnection();
try{
statement=conn.createStatement();
Stringsql="insertintogoodsvalues((selectmax(goods_id+1)fromgoods),'"+User.getUserName()+"','"+goods.getName()+"',"+goods.getPrice()+","+goods.getDiscount()+","+goods.getNum()+")";
flag=statement.executeUpdate(sql);
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
try{
statement.close();
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
returnflag;
}
publicstaticvoidmain(String[]args){
GoodsDaodao=newGoodsDao();
//Goodsgoods=newGoods();
//goods.setName("c++");
//goods.setPrice(50);
//User.setUserName("niclascage");
//goods.setDiscount(8);
//goods.setNum(10);
//System.out.println("main");
//System.out.println("ii"+dao.insertGoods(goods));
//System.out.println(dao.deleteById(4));
//Goodsgoods=newGoods();
//goods.setId
(1);
//goods.setName("oracle");
//goods.setPrice(50);
//goods.setDiscount(8);
//goods.setNum(5);
//System.out.println(dao.updateGoods(goods));
dao.getAllSellerGoods();
//Syst
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 网上 书店 完整 代码