版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、附錄 所有源代碼package com.shoeShop.db;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;public class Connect private static Connection con = null;private static String url=jdbc:oracle:thin:localhost:1521:ORCL;private static String driver = oracle.jdbc.driver.OracleDrive
2、r;private static String user = scott;private static String pwd = tiger;public static Connection getConnection()try Class.forName(driver);con = DriverManager.getConnection(url, user, pwd);System.out.println(數(shù)據(jù)庫連接成功!); catch (ClassNotFoundException e) System.out.println(驅(qū)動加載失??!); catch (SQLException e
3、) System.out.println(數(shù)據(jù)庫連接失??!);return con;public static void main(String args) Connect.getConnection();package com.shoeShop.action;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JPanel;import com.shoeShop.view.RegisterFrame;public class docMenuAction implem
4、ents ActionListener RegisterFrame register = null;JPanel cusPanel = null;JPanel docPanel = null;public docMenuAction(RegisterFrame register)this.register = register;this.cusPanel = register.cusPanel;this.docPanel = register.docPanel;public void actionPerformed(ActionEvent e) / TODO Auto-generated me
5、thod stubregister.flag = 1;/System.out.println(register.flag);register.remove(cusPanel);register.add(docPanel);docPanel.updateUI();package com.shoeShop.dao;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import com.shoeShop.db.Connect;impor
6、t com.shoeShop.entity.Buyer;import com.shoeShop.entity.Seller;public class BuyerDao private static Connection conn;private static Statement statement;private static ResultSet resultSet;/插入數(shù)據(jù),用于注冊public int insertBuyer(Buyer buyer)int flag = 0;conn = Connect.getConnection();try statement = conn.creat
7、eStatement();String sql = insert into buyer values(+buyer.getId()+,+buyer.getName()+,+buyer.getPwd()+,+buyer.getAddress()+);/System.out.println(buyer+sql);flag = statement.executeUpdate(sql);statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();/
8、System.out.println(flag);return flag;/通過顧客名和密碼查詢,用于登錄public static Buyer getBuyer(String name,String pwd)conn = Connect.getConnection();Buyer buyer = new Buyer();try statement = conn.createStatement();String sql = select * from buyer where buyer_id=+name+ and pwd = +pwd+;resultSet = statement.execut
9、eQuery(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 (SQLException e) / TODO Auto-generated
10、 catch blocke.printStackTrace();return buyer;public static void main(String args) BuyerDao dao = new BuyerDao();System.out.println(dao.getBuyer(zxk, 654321);/Buyer buyer = new Buyer();/buyer.setId(lily);/buyer.setName(長理專賣);/buyer.setPwd(123456);/buyer.setAddress(湖南長沙);/dao.insertBuyer(buyer);packag
11、e com.shoeShop.dao;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import com.shoeShop.db.Connect;import com.shoeShop.entity.Goods;import com.shoeShop.entity.Seller;import com.shoeShop.imp.User;public class GoodsD
12、ao private static Connection conn;private static Statement statement;private static ResultSet resultSet;/查詢登錄商家旳所有商品,用于商家管理自己旳商品public ArrayList getAllGoods()ArrayList list = new ArrayList();conn = Connect.getConnection();try statement = conn.createStatement();String sql = select * from goods a,sell
13、er b where a.seller_id=b.seller_id and b.seller_id=+User.getUserName()+;resultSet = statement.executeQuery(sql);while(resultSet.next()Seller seller = new Seller();seller.setName(resultSet.getString(seller_name);seller.setAddress(resultSet.getString(address);Goods goods = new Goods();goods.setSeller(
14、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();l
15、ist.add(goods); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return list;/查詢所有商家旳所有商品.用于顧客搜索商品public ArrayList getAllSellerGoods()Ar
16、rayList list = new ArrayList();conn = Connect.getConnection();try statement = conn.createStatement();String sql = select * from goods a,seller b where a.seller_id=b.seller_id;resultSet = statement.executeQuery(sql);while(resultSet.next()Seller seller = new Seller();seller.setName(resultSet.getString
17、(seller_name);seller.setAddress(resultSet.getString(address);Goods goods = new Goods();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.set
18、Num(resultSet.getInt(num);goods.setPrice(resultSet.getInt(price);/System.out.println(goods.toString();list.add(goods); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated
19、 catch blocke.printStackTrace();return list;/根據(jù)商品號查詢商品信息public Goods getOneGoods(int id)Goods goods = new Goods();conn = Connect.getConnection();try statement = conn.createStatement();String sql = select * from goods where goods_id = +id;resultSet = statement.executeQuery(sql);while(resultSet.next()
20、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 (SQLException e) / TODO Aut
21、o-generated catch blocke.printStackTrace();finallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return goods;/修改商品信息public int updateGoods(Goods goods)int flag = 0;conn = Connect.getConnection();try statement = conn.
22、createStatement();String sql = update goods set goods_name=+goods.getName()+,price =+goods.getPrice()+,discount =+goods.getDiscount()+,num=+goods.getNum()+ where goods_id=+goods.getId();flag = statement.executeUpdate(sql); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();f
23、inallytry statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return flag;/通過id刪除商品public int deleteById(int id)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();String sql = delete goods where goods_id = +id;fl
24、ag = statement.executeUpdate(sql); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return flag;/添加public int insertGoods(Goods goods)int flag = 0;conn =
25、Connect.getConnection();try statement = conn.createStatement();String sql = insert into goods values(select max(goods_id+1) from goods),+User.getUserName()+,+goods.getName()+,+goods.getPrice()+,+goods.getDiscount()+,+goods.getNum()+);flag = statement.executeUpdate(sql); catch (SQLException e) / TODO
26、 Auto-generated catch blocke.printStackTrace();finallytry statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return flag;public static void main(String args) GoodsDao dao = new GoodsDao();/Goods goods = new Goods();/goods.setName(c+);/goods.se
27、tPrice(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);/Goods goods = new Goods();/goods.setId(1);/goods.setName(oracle);/goods.setPrice(50);/goods.setDiscount(8);/
28、goods.setNum(5);/System.out.println(dao.updateGoods(goods);dao.getAllSellerGoods();/System.out.println(dao.getOneGoods(1);package com.shoeShop.dao;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import com.shoeSho
29、p.db.Connect;import com.shoeShop.entity.Goods;import com.shoeShop.entity.Order;import com.shoeShop.entity.Seller;import com.shoeShop.imp.User;public class OrderDao private static Connection conn;private static Statement statement;private static ResultSet resultSet;/插入public int inserOerderByGoods(Go
30、ods goods, int num)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();String sql = insert into orders values(select max(order_id+1) from orders),+goods.getId()+,+goods.getSeller_id()+,+User.getUserName()+,+num+);flag = statement.executeUpdate(sql); catch (SQLException
31、 e) / TODO Auto-generated catch blocke.printStackTrace();finallytry statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return flag;/查詢登錄顧客旳所有訂單public ArrayList getOrder()ArrayList list = new ArrayList();conn = Connect.getConnection();try state
32、ment = conn.createStatement();String sql = select * from orders a,seller b,goods c where a.seller_id=b.seller_id and a.goods_id=c.goods_id and a.buyer_id = +User.getUserName()+;resultSet = statement.executeQuery(sql);while(resultSet.next()Order order = new Order();Goods goods = new Goods();Seller se
33、ller = new Seller();order.setId(resultSet.getInt(order_id);order.setNum(resultSet.getInt(num);order.setGoods_id(resultSet.getInt(goods_id);goods.setId(resultSet.getInt(goods_id);goods.setPrice(resultSet.getShort(price);goods.setPrice(resultSet.getInt(price);goods.setDiscount(resultSet.getInt(discoun
34、t);goods.setName(resultSet.getString(goods_name);seller.setName(resultSet.getString(seller_name);seller.setAddress(resultSet.getString(address);order.setSeller(seller);order.setGoods(goods);/System.out.println(order.toString();list.add(order); catch (SQLException e) / TODO Auto-generated catch block
35、e.printStackTrace();finallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return list;/查詢登錄商家旳所有訂單public ArrayList getSellerOrder()ArrayList list = new ArrayList();conn = Connect.getConnection();try statement = conn.c
36、reateStatement();String sql = select * from orders a,seller b,goods c where a.seller_id=b.seller_id +and a.goods_id=c.goods_id and a.seller_id= +User.getUserName()+;resultSet = statement.executeQuery(sql);while(resultSet.next()Order order = new Order();Goods goods = new Goods();Seller seller = new S
37、eller();order.setId(resultSet.getInt(order_id);order.setNum(resultSet.getInt(num);order.setGoods_id(resultSet.getInt(goods_id);order.setBuyer_id(resultSet.getString(buyer_id);goods.setId(resultSet.getInt(goods_id);goods.setPrice(resultSet.getShort(price);goods.setPrice(resultSet.getInt(price);goods.
38、setDiscount(resultSet.getInt(discount);goods.setName(resultSet.getString(goods_name);seller.setName(resultSet.getString(seller_name);seller.setAddress(resultSet.getString(address);order.setSeller(seller);order.setGoods(goods);list.add(order); catch (SQLException e) / TODO Auto-generated catch blocke
39、.printStackTrace();finallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return list;public static void main(String args) OrderDao dao = new OrderDao();dao.getOrder();package com.shoeShop.dao;import java.sql.Connectio
40、n;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import com.shoeShop.db.Connect;import com.shoeShop.entity.Seller;public class SellerDao private static Connection conn;private static Statement statement;private static ResultSet resultSet;/插入數(shù)據(jù),用于注冊public int insertS
41、eller(Seller seller)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();String sql = insert into seller values(+seller.getId()+,+seller.getName()+,+seller.getPwd()+,+seller.getAddress()+);flag = statement.executeUpdate(sql);statement.close();conn.close(); catch (SQLExc
42、eption e) / TODO Auto-generated catch blocke.printStackTrace();return flag;/通過顧客名和密碼查詢,用于登錄public static Seller getSeller(String name,String pwd)conn = Connect.getConnection();Seller seller = new Seller();try statement = conn.createStatement();String sql = select * from seller where seller_id=+name+
43、 and pwd = +pwd+;resultSet = statement.executeQuery(sql);while(resultSet.next()seller.setId(resultSet.getString(seller_id);seller.setName(resultSet.getString(seller_name);seller.setPwd(resultSet.getString(pwd);seller.setAddress(resultSet.getString(address);resultSet.close();statement.close();conn.cl
44、ose(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return seller;public static void main(String args) SellerDao dao = new SellerDao();/System.out.println(dao.getSeller(蔣斌, 654321);/Seller seller = new Seller();/seller.setId(lily);/seller.setName(長理專賣);/seller.setPwd(1
45、23456);/seller.setAddress(湖南長沙);/dao.insertSeller(seller);package com.shoeShop.entity;/* *功能:商家實(shí)體類 * author:蔣斌 *-9-19下午4:17:40 */public class Buyer private String id;private String name;private String address;private String pwd;public String getPwd() return pwd;public void setPwd(String pwd) this.pw
46、d = pwd;public String getId() return id;public void setId(String id) this.id = id;public String getName() return name;public void setName(String name) = name;public String getAddress() return address;public void setAddress(String address) this.address = address;Overridepublic String toStri
47、ng() return Buyer id= + id + , name= + name + , address= + address+ ;package com.shoeShop.entity;/* * *功能:商品實(shí)體類 * author:蔣斌 *-9-19下午4:26:05 */public class Goods private int id;private String seller_id;private Seller seller;private String name;private int price;private int discount;private int num;pu
48、blic Seller getSeller() return seller;public void setSeller(Seller seller) this.seller = seller;public int getDiscount() return discount;public void setDiscount(int discount) this.discount = discount;public int getNum() return num;public void setNum(int num) this.num = num;public int getId() return
49、id;public void setId(int id) this.id = id;public String getSeller_id() return seller_id;public void setSeller_id(String seller_id) this.seller_id = seller_id;public String getName() return name;public void setName(String name) = name;public int getPrice() return price;public void setPrice(
50、int price) this.price = price;Overridepublic String toString() return Goods id= + id + , seller_id= + seller_id + , seller=+ seller + , name= + name + , price= + price+ , discount= + discount + , num= + num + ;package com.shoeShop.entity;/* * *功能:訂單實(shí)體類 * author:蔣斌 *-9-19下午4:26:24 */public class Orde
51、r private int id;private int goods_id;private String seller_id;private String buyer_id;private Goods goods;private Seller seller;private Buyer buyer;private int num;public int getNum() return num;public void setNum(int num) this.num = num;public Goods getGoods() return goods;public void setGoods(Goo
52、ds goods) this.goods = goods;public Seller getSeller() return seller;public void setSeller(Seller seller) this.seller = seller;public Buyer getBuyer() return buyer;public void setBuyer(Buyer buyer) this.buyer = buyer;public int getId() return id;public void setId(int id) this.id = id;public int getG
53、oods_id() return goods_id;public void setGoods_id(int goods_id) this.goods_id = goods_id;public String getSeller_id() return seller_id;public void setSeller_id(String seller_id) this.seller_id = seller_id;public String getBuyer_id() return buyer_id;public void setBuyer_id(String buyer_id) this.buyer
54、_id = buyer_id;Overridepublic String toString() return Order id= + id + , goods_id= + goods_id + , seller_id=+ seller_id + , buyer_id= + buyer_id + , goods= + goods+ , seller= + seller + , buyer= + buyer + , num= + num+ ;package com.shoeShop.entity;/* *功能:買家實(shí)體類 * author: *-9-19下午4:16:46 */public cla
55、ss Seller private String id;private String name;private String pwd;private String address;public String getPwd() return pwd;public void setPwd(String pwd) this.pwd = pwd;public String getId() return id;public void setId(String id) this.id = id;public String getName() return name;public void setName(
56、String name) = name;public String getAddress() return address;public void setAddress(String address) this.address = address;Overridepublic String toString() return Seller id= + id + , name= + name + , pwd= + pwd+ , address= + address + ;package com.shoeShop.imp;public class User private st
57、atic int flag = 0;private static String userName;private static String pwd;public static String getPwd() return pwd;public static void setPwd(String pwd) User.pwd = pwd;public static String getUserName() return userName;public static void setUserName(String userName) User.userName = userName;public
58、static int getFlag() return flag;public static void setFlag(int flag) User.flag = flag;package com.shoeShop.view;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import j
59、avax.swing.JOptionPane;import javax.swing.JTextField;import com.shoeShop.dao.GoodsDao;import com.shoeShop.entity.Goods;public class AddGoodsFrame extends JFrameprivate static final Goods Goods = null;private JLabel lbName = new JLabel(商品名:);private JLabel lbPrice = new JLabel(價格:);private JLabel lbD
60、iscount = new JLabel(折扣:);private JLabel lbNum = new JLabel(數(shù)量:);private JTextField fieldName = new JTextField(20);private JTextField fieldPrice = new JTextField(20);private JTextField fieldDiscount = new JTextField(20);private JTextField fieldNum = new JTextField(20);private JButton btSure = new JB
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年升降機(jī)租賃合同參考范文(四篇)
- 2024年安全保衛(wèi)工作總結(jié)樣本(二篇)
- 2024年合伙合同經(jīng)典版(二篇)
- 2024年學(xué)校升旗儀式管理制度范文(三篇)
- 2024年廁所管理制度廁所管理員職責(zé)例文(三篇)
- 2024年小區(qū)非機(jī)動車管理規(guī)定范文(二篇)
- 2024年場地租賃協(xié)議范本(二篇)
- 2024年幼兒園小班上學(xué)期工作計劃范例(四篇)
- 2024年員工餐廳管理制度例文(三篇)
- 【《浩源洋掃地機(jī)企業(yè)應(yīng)收賬款管理現(xiàn)狀、問題及對策》論文】
- 品管圈提高低血糖護(hù)士規(guī)范處理率
- 江蘇省南京市鼓樓區(qū)+2023-2024學(xué)年九年級上學(xué)期期中物理試題(有答案)
- 老年友善醫(yī)院創(chuàng)建匯報
- 垃圾制氫工藝流程
- 素描教案之素描基礎(chǔ)
- 2024-2030年中國絲苗米行業(yè)發(fā)展趨勢及發(fā)展前景研究報告
- 2023-2024學(xué)年廣西南寧市高一年級上冊期中考試數(shù)學(xué)質(zhì)量檢測模擬試題(含解析)
- 《行政復(fù)議法》講座課件-2024鮮版
- 股份期權(quán)協(xié)議
- 戰(zhàn)場防護(hù)基本知識課件
- GB/T 43829-2024農(nóng)村糞污集中處理設(shè)施建設(shè)與管理規(guī)范
評論
0/150
提交評論