版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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(数据库连接成功!); catch (ClassNotFoundException e) System.out.println(驱动加载失败!); catch (SQLException e
3、) System.out.println(数据库连接失败!);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;/插入数据,用于注册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, );/Buyer buyer = new Buyer();/buyer.setId(lily);/buyer.setName(长理专卖);/buyer.setPwd();/buyer.setAddress(湖南长沙);/dao.insertBuyer(buyer);package com.shoeSh
11、op.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 GoodsDao private s
12、tatic 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,seller b where a
13、.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(seller);good
14、s.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(good
15、s); 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()ArrayList list
16、 = 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
17、);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.setNum(resultSe
18、t.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 catch block
19、e.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.executeQuery(sql);while(resultSet.next()goods.setId(
20、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 Auto-generated
21、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.createStatem
22、ent();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();finallytry st
23、atement.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;flag = stateme
24、nt.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 = Connect.getC
25、onnection();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 Auto-genera
26、ted 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.setPrice(50);/
27、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);/goods.setNum
28、(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.shoeShop.db.Connect
29、;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(Goods goods, i
30、nt 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 e) / TODO A
31、uto-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 statement = conn.
32、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 = new S
33、eller();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(discount);goods.set
34、Name(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 blocke.printStack
35、Trace();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.createStateme
36、nt();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 Seller();orde
37、r.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.setDiscount(
38、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.printStackT
39、race();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.Connection;import jav
40、a.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;/插入数据,用于注册public int insertSeller(Seller
41、 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 (SQLException e) /
42、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+ and pwd = +
43、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
44、 (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(蒋斌, );/Seller seller = new Seller();/seller.setId(lily);/seller.setName(长理专卖);/seller.setPwd();/seller.setAddres
45、s(湖南长沙);/dao.insertSeller(seller);package com.shoeShop.entity;/* *功能:商家实体类 * author:蒋斌 *2012-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.pwd = pwd;public Strin
46、g 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 toString() return Buyer id
47、= + id + , name= + name + , address= + address+ ;package com.shoeShop.entity;/* * *功能:商品实体类 * author:蒋斌 *2012-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;public Seller getS
48、eller() 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 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 = se
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024至2030年覆膜胶项目投资价值分析报告
- 2024年脚踏开启周转垃圾房项目可行性研究报告
- 2024年砂岩项目可行性研究报告
- 2024至2030年中国香草节庆蛋糕行业投资前景及策略咨询研究报告
- 统考版2025届高考数学一轮复习第八章8.1空间几何体的结构及其三视图和直观图课时作业理含解析
- 2024年校园宿舍装修施工协议版
- 2024-2030年视频广告行业市场深度调研及前景趋势与投资战略研究报告
- 2024-2030年血清病毒分析仪行业市场深度调研及发展趋势与投资研究报告
- 2024-2030年蔬果保鲜剂市场投资前景分析及供需格局研究预测报告
- 2024-2030年药品行业风险投资发展分析及投资融资策略研究报告
- 智慧机关综合服务集成平台规划方案
- 文创品营销方案
- 小学心里健康教师述职报告(四篇合集)
- 第6章 金属基复合材料的界面及其表征
- 第一单元 岁月回声- 保卫黄河 课件 2023-2024学年人音版初中音乐九年级下册
- 实施书记项目工作总结
- 煤矿岗位标准化作业流程
- 新媒体视觉设计之新媒体动态交互视觉设计
- 《横纹肌溶解症》课件
- 《治安管理处罚法》课件
- 组建内镜中心的可行性方案
评论
0/150
提交评论