


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第1頁共34頁附錄全部源代碼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 s
2、tatic String driver = "oracle.jdbc.driver.OracleDriver" 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ù)
3、據(jù)庫連接成功!"); catch (ClassNotFoundException e) System.out.println(" 驅(qū)動加載失??! "); catch (SQLException e) System.out.println(" 數(shù)據(jù)庫連接失??!");return con;public static void main(String args) Connect.getConnection();專業(yè)資料整理WORD格式專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第2頁共34頁package com.
4、shoeShop.action;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JPanel;import com.shoeShop.view.RegisterFrame;public class docMenuAction implements ActionListener RegisterFrame register = null;JPanel cusPanel = null;JPanel docPanel = null;public docMenuActio
5、n(RegisterFrame register)this.register = register;this.cusPanel = register.cusPanel;this.docPanel = register.docPanel;public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub register.flag = 1; /System.out.println(register.flag); register.remove(cusPanel); register.add(docPanel);
6、 docPanel.updateUI();專業(yè)資料整理WORD格式package com.shoeShop.dao;專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第3頁共34頁import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import com.shoeShop.db.Connect;import com.shoeShop.entity.Buyer;import com.shoeShop.ent
7、ity.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.createStatement();String sql = "insert into buyer v
8、alues('"+buyer.getId()+"','"+buyer.getName()+"','"+buyer.getPwd()+"','"+buyer.getAddress()+"')" ;/System.out.println("buyer"+sql);flag = statement.executeUpdate(sql);statement.close();conn.close(); catch (SQLExcep
9、tion e) / TODO Auto-generated catch block專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第4頁共34頁e.printStackTrace();/ System.out.println(flag);return flag;/通過用戶名和密碼查詢,用于登錄public static Buyer getBuyer(String name,String pwd)conn = Connect.getConnection();Buyer buyer = new Buyer();try statement = conn.createS
10、tatement();Stringsql ="select*frombuyerwhere buyer_id='"+name+"'and pwd='"+pwd+"'"resultSet =statement.executeQuery(sql);while(resultSet.next()buyer.setId(resultSet.getString("buyer_id");buyer.setName(resultSet.getString("buyer_name")
11、;buyer.setPwd(resultSet.getString("pwd");buyer.setAddress(resultSet.getString("address");resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return buyer;專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第5頁共34頁publ
12、ic 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("* ");/ d
13、ao.insertBuyer(buyer);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.shoeShop.db.Connect;import com.shoeShop.entity.Goods;import com.shoeShop.entity.Seller;import com.shoeShop.
14、imp.User;public class GoodsDao private static Connection conn;private static Statement statement;private static ResultSet resultSet;專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第6頁共34頁/查詢登錄商家的所有商品,用于商家管理自己的商品public ArrayList getAllGoods()ArrayList list = new ArrayList();conn = Connect.getConnection();try
15、 statement = conn.createStatement();String sql = "select *from goods a,seller b where a.seller_id=b.seller_idandb.seller_id='"+User.getUserName()+"'"resultSet = statement.executeQuery(sql);while(resultSet.next()Seller seller = new Seller();seller.setName(resultSet.getStri
16、ng("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
17、");goods.setDiscount(resultSet.getInt("discount");goods.setNum(resultSet.getInt("num");goods.setPrice(resultSet.getInt("price");/System.out.println(goods.toString();list.add(goods); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();finall
18、ytry 專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第7頁共34頁resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return list;/查詢所有商家的所有商品.用于用戶搜索商品public ArrayList getAllSellerGoods()ArrayList list = new ArrayList();conn = Connect.getC
19、onnection();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("seller_name");seller.setAdd
20、ress(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.getIn
21、t("discount");goods.setNum(resultSet.getInt("num");專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第8頁共34頁goods.setPrice(resultSet.getInt("price");/System.out.println(goods.toString();list.add(goods); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();f
22、inallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return list;/根據(jù)商品號查詢商品信息public Goods getOneGoods(int id)Goods goods = new Goods();conn = Connect.getConnection();try statement = conn.createStatement();String sql
23、= "select * from goods where goods_id = "+id;resultSet = statement.executeQuery(sql);while(resultSet.next()專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第9頁共34頁goods.setId(id);goods.setName(resultSet.getString("goods_name");goods.setPrice(resultSet.getInt("price");goods.setNu
24、m(resultSet.getInt("num");goods.setDiscount(resultSet.getInt("discount");goods.setSeller_id(resultSet.getString("seller_id");goods.setNum(resultSet.getInt("num"); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry resultSet.
25、close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return goods;/修改商品信息public int updateGoods(Goods goods)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 10頁
26、共 34頁Stringsql="updategoodssetgoods_name='"+goods.getName()+"',price="+goods.getPrice()+",discount ="+goods.getDiscount()+",num="+goods.getNum()+"wheregoods_id="+goods.getId();flag = statement.executeUpdate(sql); catch (SQLException e) / TODO
27、 Auto-generated catch block e.printStackTrace();finallytry statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return flag;/通過 id 刪除商品public int deleteById(int id)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement
28、();String sql = "delete goods where goods_id = "+id;flag = statement.executeUpdate(sql); catch (SQLException e) 專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 11頁共 34頁/ TODO Auto-generated catch block e.printStackTrace();finallytry statement.close();conn.close(); catch (SQLException e) / TODO A
29、uto-generated catch block e.printStackTrace();return flag;/添加public int insertGoods(Goods goods)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();Stringsql="insertintogoodsvalues(selectmax(goods_id+1)fromgoods),'"+User.getUserName()+"','&qu
30、ot;+goods.getName()+"',"+goods.getPrice()+","+goods.getDiscount()+","+goods.getNum()+")"flag = statement.executeUpdate(sql); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();finallytry statement.close();專業(yè)資料整理WORD格式"網(wǎng)上書店信息管
31、理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 12頁共 34頁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.setPrice(50);/ User.setUserName("
32、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);/
33、 goods.setDiscount(8);/ goods.setNum(5);/ System.out.println(dao.updateGoods(goods);dao.getAllSellerGoods();/ System.out.println(dao.getOneGoods(1);專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 13頁共 34頁package com.shoeShop.dao;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLExcep
34、tion;import java.sql.Statement;import java.util.ArrayList;import com.shoeShop.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 stat
35、ement;private static ResultSet resultSet;/插入public int inserOerderByGoods(Goods goods, int num)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();Stringsql="insertintoordersvalues(selectmax(order_id+1)fromorders),"+goods.getId()+",'"+goods.getS
36、eller_id()+"','"+User.getUserName()+"',"+num+")"flag = statement.executeUpdate(sql); catch (SQLException e) 專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 14頁共 34頁/ TODO Auto-generated catch block e.printStackTrace();finallytry statement.close();conn.close(); cat
37、ch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return flag;/查詢登錄用戶的所有訂單public ArrayList getOrder()ArrayList list = new ArrayList();conn = Connect.getConnection();try statement = conn.createStatement();String sql = "select * fromorders a,seller b,goods c where a.seller
38、_id=b.seller_idand 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 seller = new Seller();order.setId(resultSet.getInt("order_id");
39、order.setNum(resultSet.getInt("num");order.setGoods_id(resultSet.getInt("goods_id");專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 15頁共 34頁goods.setId(resultSet.getInt("goods_id");goods.setPrice(resultSet.getShort("price");goods.setPrice(resultSet.getInt("pric
40、e");goods.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);/System.out
41、.println(order.toString();list.add(order); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();finallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return list;專業(yè)資料整理WORD格式/查詢登錄商家的所有訂單專業(yè)資料整理W
42、ORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 16頁共 34頁public ArrayList getSellerOrder()ArrayList list = new ArrayList();conn = Connect.getConnection();try statement = conn.createStatement();String sql = "select * from orders a,seller b,goods c where a.seller_id=b.seller_id "+"and a.goods_id=c.go
43、ods_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 Seller();order.setId(resultSet.getInt("order_id");order.setNum(resultSet.getInt(&quo
44、t;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.setDiscou
45、nt(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 (SQLExceptio
46、n e) 專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 17頁共 34頁/ TODO Auto-generated catch block e.printStackTrace();finallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return list;public static void main(String args) Orde
47、rDao dao = new OrderDao();dao.getOrder();package com.shoeShop.dao;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;專業(yè)資料整理WORD格式import com.shoeShop.db.Connect;專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 18頁共 34頁import com.shoeShop.entity.Seller
48、;public class SellerDao private static Connection conn;private static Statement statement;private static ResultSet resultSet;/插入數(shù)據(jù),用于注冊public int insertSeller(Seller seller)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();String sql = "insert into seller values
49、('"+seller.getId()+"','"+seller.getName()+"','"+seller.getPwd()+"','"+seller.getAddress()+"')"flag = statement.executeUpdate(sql);statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.pri
50、ntStackTrace();return flag;/通過用戶名和密碼查詢,用于登錄public static Seller getSeller(String name,String pwd)conn = Connect.getConnection();Seller seller = new Seller();try statement = conn.createStatement();專業(yè)資料整理WORD格式"網(wǎng)上書店信息管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)"第 19頁共 34頁String sql = "select * from seller where seller_i
51、d='"+name+"'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.close(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();return seller;public static void main(String args) SellerDao dao = new Selle
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《軟件開發(fā)方法》課件:掌握現(xiàn)代軟件開發(fā)流程與技術(shù)
- 社團(tuán)競選3鐘演講稿
- 《項(xiàng)目挑戰(zhàn)分析》課件
- 新版課件(黃):手衛(wèi)生:保護(hù)自己和他人免受感染的有效方式
- 《探究有理數(shù)的乘法》課件
- 《宮頸涂片檢查》課件
- 外貿(mào)單證實(shí)訓(xùn)課件
- 《先秦時期的禮制文化教案》課件
- 《金屬加工機(jī)床夾具介紹》課件
- 2025標(biāo)準(zhǔn)車輛買賣合同
- 礦業(yè)技術(shù)服務(wù)合同協(xié)議
- 特種作業(yè)培訓(xùn)取證合同協(xié)議
- 2024年黑龍江鶴崗公開招聘社區(qū)工作者考試試題答案解析
- 老舊小區(qū)改造監(jiān)理實(shí)施細(xì)則
- 退行性腰椎滑脫癥診療指南(2025年版)課件
- 車間沖壓模具管理制度
- 2025年春初中語文七年級下冊教案設(shè)計(jì) 15 青春之光
- 2021碳纖維復(fù)合芯導(dǎo)線配套金具技術(shù)條件 第2部分:接續(xù)管
- 語言學(xué)概論知到課后答案智慧樹章節(jié)測試答案2025年春湖州師范學(xué)院
- 2025-2030中國印刷電路板(PCB)行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報(bào)告
- 天津東疆綜合保稅區(qū)管理委員會招聘筆試真題2024
評論
0/150
提交評論