收藏 分享(赏)

网上书店完整代码.doc

上传人:精品资料 文档编号:8539715 上传时间:2019-07-02 格式:DOC 页数:69 大小:230KB
下载 相关 举报
网上书店完整代码.doc_第1页
第1页 / 共69页
网上书店完整代码.doc_第2页
第2页 / 共69页
网上书店完整代码.doc_第3页
第3页 / 共69页
网上书店完整代码.doc_第4页
第4页 / 共69页
网上书店完整代码.doc_第5页
第5页 / 共69页
点击查看更多>>
资源描述

1、 网上书店信息管理系统的设计与实现 第 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 static String driver

2、= “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(“数据库连接成功!“); catch (ClassNotFoundException e) System.out

3、.println(“驱动加载失败!“); catch (SQLException e) System.out.println(“数据库连接失败!“);return con;public static void main(String args) Connect.getConnection();网上书店信息管理系统的设计与实现 第 2 页 共 34 页package com.shoeShop.action;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JPanel

4、;import com.shoeShop.view.RegisterFrame;public class docMenuAction implements ActionListener RegisterFrame register = null;JPanel cusPanel = null;JPanel docPanel = null;public docMenuAction(RegisterFrame register)this.register = register;this.cusPanel = register.cusPanel;this.docPanel = register.doc

5、Panel;public void actionPerformed(ActionEvent e) / TODO Auto-generated method stubregister.flag = 1;/System.out.println(register.flag);register.remove(cusPanel);register.add(docPanel);docPanel.updateUI();package com.shoeShop.dao;网上书店信息管理系统的设计与实现 第 3 页 共 34 页import java.sql.Connection;import java.sql

6、.ResultSet;import java.sql.SQLException;import java.sql.Statement;import com.shoeShop.db.Connect;import com.shoeShop.entity.Buyer;import com.shoeShop.entity.Seller;public class BuyerDao private static Connection conn;private static Statement statement;private static ResultSet resultSet;/插入数据,用于注册pub

7、lic int insertBuyer(Buyer buyer)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();String sql = “insert into buyer values(“+buyer.getId()+“,“+buyer.getName()+“,“+buyer.getPwd()+“,“+buyer.getAddress()+“)“;/ System.out.println(“buyer“+sql);flag = statement.executeUpdate

8、(sql);statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();网上书店信息管理系统的设计与实现 第 4 页 共 34 页/ System.out.println(flag);return flag;/通过用户名和密码查询,用于登录public static Buyer getBuyer(String name,String pwd)conn = Connect.getConnection();Buyer buyer = new B

9、uyer();try statement = conn.createStatement();String sql = “select * from buyer where 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“);buyer.setPwd(resultSet.g

10、etString(“pwd“);buyer.setAddress(resultSet.getString(“address“);resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return buyer;网上书店信息管理系统的设计与实现 第 5 页 共 34 页public static void main(String args) BuyerDao dao = new BuyerDao();S

11、ystem.out.println(dao.getBuyer(“zxk“, “654321“);/ Buyer buyer = new Buyer();/ buyer.setId(“lily“);/ buyer.setName(“长理专卖 “);/ buyer.setPwd(“123456“);/ buyer.setAddress(“湖南长沙 “);/ dao.insertBuyer(buyer);package com.shoeShop.dao;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLEx

12、ception;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 GoodsDao private static Connection conn;private static Statement statement;private static ResultSet

13、 resultSet;/查询登录商家的所有商品,用于商家管理自己的商品网上书店信息管理系统的设计与实现 第 6 页 共 34 页public ArrayList getAllGoods()ArrayList 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 and b.seller_id=“+User.getUs

14、erName()+“;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(seller);goods.setId(resultSet.getInt(“goods_id“);goods.se

15、tName(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 (SQLException e) / TOD

16、O Auto-generated catch blocke.printStackTrace();finallytry resultSet.close();网上书店信息管理系统的设计与实现 第 7 页 共 34 页statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return list;/查询所有商家的所有商品.用于用户搜索商品public ArrayList getAllSellerGoods()ArrayList list =

17、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(“seller_name

18、“);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.setN

19、um(resultSet.getInt(“num“);goods.setPrice(resultSet.getInt(“price“);网上书店信息管理系统的设计与实现 第 8 页 共 34 页/ 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 (SQLE

20、xception e) / TODO Auto-generated catch blocke.printStackTrace();return list;/根据商品号查询商品信息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.execu

21、teQuery(sql);while(resultSet.next()goods.setId(id);网上书店信息管理系统的设计与实现 第 9 页 共 34 页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_

22、id“);goods.setNum(resultSet.getInt(“num“); 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 goods;/修改商品信息public int updateGoods(G

23、oods goods)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();String sql = “update goods set goods_name=“+goods.getName()+“,price 网上书店信息管理系统的设计与实现 第 10 页 共 34 页=“+goods.getPrice()+“,discount =“+goods.getDiscount()+“,num=“+goods.getNum()+“ where goods_id=“+goods.getId(

24、);flag = 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;/通过 id 删除商品public int deleteById(int id)int flag = 0;c

25、onn = Connect.getConnection();try statement = conn.createStatement();String sql = “delete goods where goods_id = “+id;flag = statement.executeUpdate(sql); catch (SQLException e) / TODO Auto-generated catch block网上书店信息管理系统的设计与实现 第 11 页 共 34 页e.printStackTrace();finallytry statement.close();conn.close

26、(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return flag;/添加public int insertGoods(Goods goods)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();String sql = “ insert into goods values(select max(goods_id+1) from goods),“+User.getUs

27、erName()+“,“+goods.getName()+“,“+goods.getPrice()+“,“+goods.getDiscount()+“,“+goods.getNum()+“)“;flag = statement.executeUpdate(sql); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry statement.close();conn.close();网上书店信息管理系统的设计与实现 第 12 页 共 34 页 catch (SQLExcepti

28、on 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(“niclascage“);/ goods.setDiscount(8);/ goods.setNum(10);/ System.out.pri

29、ntln(“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);/ goods.setNum(5);/ System.out.println(dao.updateGoods(goods);dao.getAllSellerGoods(

30、);/ System.out.println(dao.getOneGoods(1);网上书店信息管理系统的设计与实现 第 13 页 共 34 页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;impo

31、rt 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(Goods goods, int num)int flag = 0;conn = Connect.get

32、Connection();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 e) / TODO Auto-generated catch block网上书

33、店信息管理系统的设计与实现 第 14 页 共 34 页e.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 statement = con

34、n.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 seller =

35、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“);网上书店信息管理系统的设计与实现 第 15 页 共 34 页goods.setPrice(resultSet.getShort(“price“);goods.setPrice(resultSet.getInt(“price“);goods.s

36、etDiscount(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.println(order.toString();list.add(order); catch (SQLEx

37、ception 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 getSellerOrder()网上书店信息管理系统的设计与实现 第 16 页 共 34 页ArrayList li

38、st = 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.goods_id and a.seller_id= “+User.getUserName()+“;resultSet = statement.executeQuery(sql);while(resultSet

39、.next()Order order = new Order();Goods goods = new Goods();Seller seller = new Seller();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_i

40、d“);goods.setPrice(resultSet.getShort(“price“);goods.setPrice(resultSet.getInt(“price“);goods.setDiscount(resultSet.getInt(“discount“);goods.setName(resultSet.getString(“goods_name“);seller.setName(resultSet.getString(“seller_name“);seller.setAddress(resultSet.getString(“address“);order.setSeller(se

41、ller);order.setGoods(goods);list.add(order); catch (SQLException e) / TODO Auto-generated catch block网上书店信息管理系统的设计与实现 第 17 页 共 34 页e.printStackTrace();finallytry resultSet.close();statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return list;

42、public static void main(String args) OrderDao 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;import com.shoeShop.db.Connect;import com.shoeShop.entity.Seller;网上书店信息管理系统的设计与实现 第 1

43、8 页 共 34 页public class SellerDao private static Connection conn;private static Statement statement;private static ResultSet resultSet;/插入数据,用于注册public int insertSeller(Seller seller)int flag = 0;conn = Connect.getConnection();try statement = conn.createStatement();String sql = “insert into seller va

44、lues(“+seller.getId()+“,“+seller.getName()+“,“+seller.getPwd()+“,“+seller.getAddress()+“)“;flag = statement.executeUpdate(sql);statement.close();conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return flag;/通过用户名和密码查询,用于登录public static Seller getSeller(String

45、 name,String pwd)conn = Connect.getConnection();Seller seller = new Seller();try statement = conn.createStatement();String sql = “select * from seller where seller_id=“+name+“ and pwd = 网上书店信息管理系统的设计与实现 第 19 页 共 34 页“+pwd+“;resultSet = statement.executeQuery(sql);while(resultSet.next()seller.setId(r

46、esultSet.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 blocke.printStackTrace();re

47、turn 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(“123456“);/ seller.setAddress(“湖南长沙“);/ dao.insertSeller(seller);网上书店信息管理

48、系统的设计与实现 第 20 页 共 34 页package com.shoeShop.entity;/*功能:商家实体类* author:蒋斌*2012-9-19 下午 4:17:40*/public class Buyer private String id;private String name;private String address;网上书店信息管理系统的设计与实现 第 21 页 共 34 页private String pwd;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;publ

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报