基于数据库的餐厅管理系统

package text;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class function {
	 //连接对象
    Connection connection=null;
    //创建预编译对象
    PreparedStatement ps=null;
    //创建结果集
    ResultSet rs = null;
    Scanner scan = new Scanner(System.in);
	 public void selectcostomer() throws SQLException{
	        connection = cwd.getCon();
	        String sql = "select * from costomer where gno = ?";
	        try {
	            ps = connection.prepareStatement(sql);
	            Scanner scan = new Scanner(System.in);
	            System.out.println("请输入要查询的顾客的编号号:");
	            String  gno = scan.next();
	            ps.setString(1,gno);
	            rs = ps.executeQuery();
	            while (rs.next()){
	                String Gno = rs.getString(1);
	                String gname = rs.getString(2);
	                String zno = rs.getString(3);
	                String ghost = rs.getString(4);
	                String gmember = rs.getString(5);
	                String gremark= rs.getString(6);
	                System.out.println("编号:"+Gno);
	                System.out.println("姓名:"+gname);
	                System.out.println("餐桌:"+zno);
	                System.out.println("开单人:"+ghost);
	                System.out.println("会员:"+gmember);
	                System.out.println("备注:"+gremark);
	             }
	            System.out.printf("查询成功 ");
	        } catch (SQLException e) {
	            e.printStackTrace();
	        }finally {
	            cwd.closeCon(connection);
	        }
	    }
	
	 
	 public void selectoc() throws SQLException{
	        connection = cwd.getCon();
	        String sql = "select gname,cname,os from costomer,commodity,oc where costomer.gno=oc.gno and commodity.cno=oc.cno ";
	        try {
	            ps = connection.prepareStatement(sql);
	            Scanner scan = new Scanner(System.in);
	           
	            rs = ps.executeQuery();
	            while (rs.next()){
	                String gname = rs.getString(1);
	                String cname = rs.getString(2);
	                String os = rs.getString(3);
	                System.out.println("顾客姓名:"+gname);
	                System.out.println("商品姓名:"+cname);
	                System.out.println("满意度:"+os);
	               
	             }
	            System.out.printf("查询成功 ");
	        } catch (SQLException e) {
	            e.printStackTrace();
	        }finally {
	            cwd.closeCon(connection);
	        }
	    }
	
	 
	 public void selectsweep() throws SQLException{
	        connection = cwd.getCon();
	        String sql = "select sname,zlo from staff,fanzhuo,sweep where staff.sno=sweep.sno and fanzhuo.zno=sweep.zno";
	        try {
	            ps = connection.prepareStatement(sql);
	            Scanner scan = new Scanner(System.in);
	            rs = ps.executeQuery();
	            while (rs.next()){
	                String sname = rs.getString(1);
	                String zno = rs.getString(2);
	                System.out.println("打扫职工的姓名:"+sname);
	                System.out.println("打扫餐桌的位置:"+zno);
	               
	             }
	            System.out.printf("查询成功 ");
	        } catch (SQLException e) {
	            e.printStackTrace();
	        }finally {
	            cwd.closeCon(connection);
	        }
	    }
	 
	 
	 public int insertcostomer() throws SQLException{ 
		 int result = 0; 
		 connection =  cwd.getCon(); 
		 System.out.printf("请输入插入顾客信息");
		String sql = "insert into costomer values(?,?,?,?,?,?)";
	try { 
		//数据库信息
		 /*gno char(7) not null primary key,
        gname varchar2(50) not null,
        zno char(2) not null,
        ghost varchar2(50) not null,     
        gmember char(4) not null check(gmember in('是','否')),
        gremark varchar2(150),*/
		String gno=scan.next();           
		String gname=scan.next();        
		String zno=scan.next();            
		String ghost=scan.next();
		String gmember=scan.next();
		String g=scan.next();
		ps =  connection.prepareStatement(sql); 
	      ps.setString(1,gno);
	      ps.setString(2,gname); 
	      ps.setString(3,zno); 
	      ps.setString(4,ghost);
	      ps.setString(5,gmember);
	      ps.setString(6,g);
	      result = ps.executeUpdate(); 
	      System.out.printf(" 插入成功 ");
		

	      } 
		catch (SQLException e) 
		{ 
			e.printStackTrace();
		 }
		finally { 
			cwd.closeCon(connection); 
		} 
		return result;
	}
	
	 
	 public int updatecostomer() throws SQ
  • 3
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值