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
基于数据库的餐厅管理系统
最新推荐文章于 2024-04-23 20:26:11 发布