题目要求
模拟肯德基快餐店的收银系统,合理使用C++或Java或Python结合设计模式(2种以上)至少实现系统的以下功能:
1.正常餐品结算和找零。
2.基本套餐结算和找零。
3.使用优惠劵购买餐品结算和找零。
4.可在一定时间段参与店内活动(自行设计或参考官网信息)。
5.模拟打印小票的功能(写到文件中)。
基本要求:
1.程序设计风格良好,控制台界面友好,最多两人一组完成任务。
2.实现功能测试代码,确保程序的健壮性。
3.画出使用的设计模式图。
提高要求:
1.实现可视化界面(使用MFC)。
2.实现会员储值卡功能,完成储值卡消费。
3.实现当天营业额和餐品销量计算和统计,用数据库记录。
相关设计模式
简单工厂模式、抽象工厂模式和单例模式。
设计模式图
部分代码
简单工厂类
public class SimpleFactory {
public static Food setFood(Class c) {
try {
return (Food) Class.forName(c.getName()).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}
抽象工厂类
public interface ComboFactory {
public Set<Food> setCombo();
}
套餐
public class Combo1 implements ComboFactory{
@Override
public Set<Food> setCombo() {
//炸鸡肥宅水套餐
Set<Food> foodOneList= new HashSet<Food>();
Food chick = new Chicken();//实例化套餐内的产品
Food cola = new Cola();
chick.price = chick.price-2;//套餐的优惠,炸鸡价格减两元
cola.price = cola.price-1;
foodOneList.add(chick);
foodOneList.add(cola);
return foodOneList;//返回套餐集合
}
}
部分食品类
public abstract class Food {
public Double price;
public String name;
public abstract double getPrice();
public int hashCode()
{
return name.hashCode();
}
public boolean equals(Object obj)
{
Food food=(Food)obj;
if(obj==null)
return false;
if(this.name.equals(food.name)&&this.price.equals(food.price))
return true;
else
return false;
}
}
public abstract class Eat extends Food {
Double quailty;
}
public abstract class Drink extends Food {
Double capacity;
}
public class Coffee extends Drink {
public Coffee() {
// TODO 自动生成的构造函数存根
name="咖啡";
price=5.0;
capacity=500.0;
}
@Override
public double getPrice() {
// TODO 自动生成的方法存根
return price;
}
}
public class Chicken extends Eat {
public Chicken() {
// TODO 自动生成的构造函数存根
name="炸鸡";
price=6.0;
quailty=0.069;
}
@Override
public double getPrice() {
// TODO 自动生成的方法存根
return price;
}
}
可视化界面
public class HomePage extends JFrame{
JButton orderButton;
JButton checkButton;
JButton printButton;
JButton storageButton;
public HomePage(){
setBg();
orderButton = new JButton("点餐");
checkButton = new JButton("介绍");
printButton = new JButton("优惠");
storageButton = new JButton("退出");
this.setTitle("KFC");
this.setSize(600,400);
this.setLocation(300, 100);
this.setLayout(null);
orderButton.setBounds(120,130,60,30);
this.add(orderButton);
orderButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
OrderyFrame orderyFrame = new OrderyFrame();
orderyFrame.setFrame(orderyFrame);
orderyFrame.MyFrame();
}
});
checkButton.setBounds(400,130,60,30);
this.add(checkButton);
checkButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//CheckFrame check = new CheckFrame();
IntroFrame introFrame = new IntroFrame();
}
});
printButton.setBounds(120,200,60,30);
this.add(printButton);
printButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//PrintFrame print = new PrintFrame();
Date time1 = new Date();
int hour=time1.getHours();
if(hour>12&&hour<13) {
JOptionPane.showMessageDialog(
null,
"现在是优惠时间,任意商品5折优惠",
"0.0",
JOptionPane.INFORMATION_MESSAGE
);}
else {JOptionPane.showMessageDialog(
null,
"很抱歉,现在不是优惠时间段!",
"0.0",
JOptionPane.INFORMATION_MESSAGE
);}
}
});
storageButton.setBounds(400,200,60,30);
this.add(storageButton);
storageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//StorageFrame storage = new StorageFrame();
dispose();
}
});
JLabel label = new JLabel("欢迎来到KFC",JLabel.CENTER);
label.setFont(new Font("宋体",Font.PLAIN,20));
label.setBounds( 200, 10, 200, 80);
this.add(label);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void setBg(){
((JPanel)this.getContentPane()).setOpaque(false);
ImageIcon img = new ImageIcon
("kfc.gif");
JLabel background = new JLabel(img);
this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
}
package Windows;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class IntroFrame extends JFrame{
public IntroFrame() {
setBg();
this.setLayout(null);
this.setTitle("KFC");
this.setSize(600,400);
this.setLocation(300, 100);
this.setLayout(null);
JLabel label1 = new JLabel("KFC's introduce",JLabel.CENTER);
label1.setFont(new Font("宋体",Font.PLAIN,20));
label1.setBounds( 200, 10, 200, 80);
String string = "“欢迎光临本店”、“尽情自在肯德基”。";
JLabel label2 = new JLabel(string);
label2.setBounds( 100, 90, 300, 80);
String string3 = "本店有随机抽取优惠卷活动,只要下单即可获得随机优惠卷";
JLabel label3 = new JLabel(string3);
label3.setBounds( 100, 150, 400, 80);
String string4 = "凡是在12:00到13:00之间下单的顾客可享受5折优惠";
JLabel label4 = new JLabel(string4);
label4.setBounds( 100, 210, 400, 80);
this.add(label1);
this.add(label2);
this.add(label3);
this.add(label4);
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void setBg(){
((JPanel)this.getContentPane()).setOpaque(false);
ImageIcon img = new ImageIcon
("kfc.gif");
JLabel background = new JLabel(img);
this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
}
package Windows;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import Meals.*;
import java.io.File;
import java.io.Writer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import ComboMeal.*;
import ComboMeal.ComboFactory;
public class OrderyFrame extends JFrame{
public static int n1=0,n2=0,n3=0,n4=0,n5=0,n6=0,t1=0,t2=0,t3=0;
/*炸鸡,汉堡,薯条,咖啡,果汁,可乐*/
Connection conn =null;
PreparedStatement ptmt =null;
Statement createStatement =null;
ResultSet rSet =null;
public static Set<Food> menuSet = new HashSet<>();
public File file=new File("小票.txt");
Paywin payframe=Paywin.getInstance();
private OrderyFrame q;
public void setFrame(OrderyFrame qq) {
q = qq;
}
public void MyFrame() {
setBg();
setTitle("KFC界面");
this.setSize(700,400);
this.setLocation(300, 100);
this.setLayout(null);
JLabel label = new JLabel("欢迎来到KFC点餐",JLabel.CENTER);
label.setFont(new Font("宋体",Font.PLAIN,20));
label.setBounds( 200, 10, 200, 80);
this.add(label);
String str1 = "主食";
JLabel label_1 = new JLabel(str1);
label_1.setFont(new Font("宋体",Font.PLAIN,15));
label_1.setBounds( 100, 60, 240, 80);
this.add(label_1);
String str2 = "饮料";
JLabel label_2 = new JLabel(str2);
label_2.setFont(new Font("宋体",Font.PLAIN,15));
label_2.setBounds( 280, 60, 240, 80);
this.add(label_2);
String str3 = "套餐";
JLabel label_3 = new JLabel(str3);
label_3.setFont(new Font("宋体",Font.PLAIN,15));
label_3.setBounds( 480, 60, 240, 80);
this.add(label_3);
String food1 = "炸鸡";
JCheckBox checkBox1 = new JCheckBox(food1);
checkBox1.setFont(new Font("宋体",Font.PLAIN,15));
checkBox1.setBounds( 100, 110, 90, 70);
this.add(checkBox1);
JLabel priceLabel1 = new JLabel("6元");
priceLabel1.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel1.setBounds( 190, 110, 100, 70);
this.add(priceLabel1);
checkBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
if (checkBox.isSelected()) {
n1+=1;
menuSet.add(SimpleFactory.setFood(Chicken.class));
}else {
n1-=1;
menuSet.remove(SimpleFactory.setFood(Chicken.class));
}
}
});
String food2 = "汉堡";
JCheckBox checkBox2 = new JCheckBox(food2);
checkBox2.setFont(new Font("宋体",Font.PLAIN,15));
checkBox2.setBounds( 100, 160, 90, 70);
this.add(checkBox2);
JLabel priceLabel2 = new JLabel("9元");
priceLabel2.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel2.setBounds( 190, 160, 100, 70);
this.add(priceLabel2);
checkBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
if (checkBox.isSelected()) {
n2+=1;
menuSet.add(SimpleFactory.setFood(Hamburger.class));
}else {
n2-=1;
menuSet.remove(SimpleFactory.setFood(Hamburger.class));
}
}
});
String food3 = "薯条";
JCheckBox checkBox3 = new JCheckBox(food3);
checkBox3.setFont(new Font("宋体",Font.PLAIN,15));
checkBox3.setBounds( 100, 210, 90, 70);
this.add(checkBox3);
JLabel priceLabel3 = new JLabel("5元");
priceLabel3.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel3.setBounds( 190, 210, 100, 70);
this.add(priceLabel3);
checkBox3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
if (checkBox.isSelected()) {
n3+=1;
menuSet.add(SimpleFactory.setFood(Chips.class));
}else {
n3-=1;
menuSet.remove(SimpleFactory.setFood(Chips.class));
}
}
});
String food4 = "咖啡";
JCheckBox checkBox4 = new JCheckBox(food4);
checkBox4.setFont(new Font("宋体",Font.PLAIN,15));
checkBox4.setBounds( 280, 110, 90, 70);
this.add(checkBox4);
JLabel priceLabel4 = new JLabel("5元");
priceLabel4.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel4.setBounds(370, 110, 90, 70);
this.add(priceLabel4);
checkBox4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
if (checkBox.isSelected()) {
n4+=1;
menuSet.add(SimpleFactory.setFood(Coffee.class));
}else {
n4-=1;
menuSet.remove(SimpleFactory.setFood(Coffee.class));
}
}
});
String food5 = "果汁";
JCheckBox checkBox5 = new JCheckBox(food5);
checkBox5.setFont(new Font("宋体",Font.PLAIN,15));
checkBox5.setBounds( 280, 160, 90, 70);
this.add(checkBox5);
JLabel priceLabel5 = new JLabel("5元");
priceLabel5.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel5.setBounds(370, 160, 100, 70);
this.add(priceLabel5);
checkBox5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
if (checkBox.isSelected()) {
n5+=1;
menuSet.add(SimpleFactory.setFood(Juice.class));
}else {
n5-=1;
menuSet.remove(SimpleFactory.setFood(Juice.class));
}
}
});
String food6 = "可乐";
JCheckBox checkBox6 = new JCheckBox(food6);
checkBox6.setFont(new Font("宋体",Font.PLAIN,15));
checkBox6.setBounds( 280, 210, 90, 70);
this.add(checkBox6);
JLabel priceLabel6 = new JLabel("5元");
priceLabel6.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel6.setBounds(370, 210, 100, 70);
this.add(priceLabel6);
checkBox6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
if (checkBox.isSelected()) {
n6+=1;
menuSet.add(SimpleFactory.setFood(Cola.class));
}else {
n6-=1;
menuSet.remove(SimpleFactory.setFood(Cola.class));
}
}
});
String food7 = "汉堡咖啡套餐";
JCheckBox checkBox7 = new JCheckBox(food7);
checkBox7.setFont(new Font("宋体",Font.PLAIN,15));
checkBox7.setBounds( 480, 110, 120, 70);
this.add(checkBox7);
JLabel priceLabel7 = new JLabel("12.5元");
priceLabel7.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel7.setBounds(610, 110, 100, 70);
this.add(priceLabel7);
checkBox7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
ComboFactory c1=new Combo3();
Set<Food> s1=c1.setCombo();
if (checkBox.isSelected()) {
t3+=1;
menuSet.addAll(s1);
}else {
t3-=1;
menuSet.removeAll(s1);
}
}
});
String food8 = "炸鸡可乐套餐";
JCheckBox checkBox8 = new JCheckBox(food8);
checkBox8.setFont(new Font("宋体",Font.PLAIN,15));
checkBox8.setBounds( 480, 160,120, 70);
this.add(checkBox8);
JLabel priceLabel8 = new JLabel("8元");
priceLabel8.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel8.setBounds(610, 160, 100, 70);
this.add(priceLabel8);
checkBox8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
ComboFactory c1=new Combo1();
Set<Food> s1=c1.setCombo();
if (checkBox.isSelected()) {
t1+=1;
menuSet.addAll(s1);
}else {
t1-=1;
menuSet.removeAll(s1);
}
}
});
String food9 = "薯条果汁套餐";
JCheckBox checkBox9 = new JCheckBox(food9);
checkBox9.setFont(new Font("宋体",Font.PLAIN,15));
checkBox9.setBounds( 480, 210, 120, 70);
this.add(checkBox9);
JLabel priceLabel9 = new JLabel("8.5元");
priceLabel9.setFont(new Font("宋体",Font.PLAIN,15));
priceLabel9.setBounds(610, 210, 100, 70);
this.add(priceLabel9);
checkBox9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
JCheckBox checkBox = (JCheckBox) e.getSource();
ComboFactory c1=new Combo2();
Set<Food> s1=c1.setCombo();
if (checkBox.isSelected()) {
t2+=1;
System.out.println("a1");
menuSet.addAll(s1);
}else {
t2-=1;
menuSet.removeAll(s1);
System.out.println("a2");
}
}
});
JButton b1 = new JButton("预定");
b1.setBounds(450, 300, 60, 30);
this.add(b1);
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
float price1 = 0,price2 = 0;
PreparedStatement st =null;
try {
conn = JDBCUtil.getConn();
if(n1!=0) {
st =conn.prepareStatement("insert into table1 values('chicken',?,?)");
st.setInt(1, n1);
st.setInt(2, 6*n1);
st.executeUpdate();
}
if(n2!=0) {
st =conn.prepareStatement("insert into table1 values('hamburger',?,?)");
st.setInt(1, n2);
st.setInt(2, 9*n2);
st.executeUpdate();
}
if(n3!=0) {
st =conn.prepareStatement("insert into table1 values('chips',?,?)");
st.setInt(1, n3);
st.setInt(2, 5*n3);
st.executeUpdate();
}
if(n4!=0) {
st =conn.prepareStatement("insert into table1 values('coffee',?,?)");
st.setInt(1, n4);
st.setInt(2, 5*n4);
st.executeUpdate();
}
if(n5!=0) {
st =conn.prepareStatement("insert into table1 values('juice',?,?)");
st.setInt(1, n5);
st.setInt(2, 5*n5);
st.executeUpdate();
}
if(n6!=0) {
st =conn.prepareStatement("insert into table1 values('cola',?,?)");
st.setInt(1, n6);
st.setInt(2, 5*n6);
st.executeUpdate();
}
if(t1!=0) {
st =conn.prepareStatement("insert into table2 values('combo1',?,?)");
st.setInt(1, t1);
st.setFloat(2, (float) (8*t1));
st.executeUpdate();
}
if(t2!=0) {
st =conn.prepareStatement("insert into table2 values('combo2',?,?)");
st.setInt(1, t2);
st.setFloat(2, (float) (8.5*n6));
st.executeUpdate();
}
if(t3!=0) {
st =conn.prepareStatement("insert into table2 values('combo3',?,?)");
st.setInt(1, t3);
st.setFloat(2, (float) (12.5*t3));
st.executeUpdate();
}
} catch (SQLException | NullPointerException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}finally {
JDBCUtil.release(conn, createStatement, rSet);
}
Connection conn =null;
Statement createStatement =null;
ResultSet rSet =null;
try {
conn = JDBCUtil.getConn();
createStatement = conn.createStatement();
//查询
String sql="select sum(ptotal) from table1";
createStatement.execute(sql); //execute执行
//返回结果
rSet =createStatement.executeQuery(sql);
while(rSet.next()) {
price1=rSet.getFloat(1);
System.out.println(rSet.getFloat(1));
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}finally {
JDBCUtil.release(conn, createStatement, rSet);
}
try {
conn = JDBCUtil.getConn();
createStatement = conn.createStatement();
//查询
String sql="select sum(tptotal) from table2";
createStatement.execute(sql); //execute执行
//返回结果
rSet =createStatement.executeQuery(sql);
while(rSet.next()) {
price2=rSet.getFloat(1); //获取聚集函数sum时不确定长度时用ResaultSet.getlong(1);
System.out.println(rSet.getFloat(1));
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("套餐的总收益为:"+price2);
System.out.println("单品的总收益为:"+price1);
System.out.println("当日收益总额为:"+price1+price2);
if(price1!=0&&price2!=0) {
try {
st =conn.prepareStatement("insert into table3 values(?,?,?)");
st.setFloat(1, price1);
st.setFloat(2, price2);
st.setFloat(3, price1+price2);
st.executeUpdate();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}finally {
JDBCUtil.release(conn, createStatement, rSet);
}
}
JOptionPane.showMessageDialog(
q,
"预定成功",
"0.0",
JOptionPane.INFORMATION_MESSAGE
);
try {
//获取当前的日期
Date date = new Date();
//设置要获取到什么样的时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//获取String类型的时间
String createdate = sdf.format(date);
Writer out = new FileWriter(file,true);
out.write("-------------------------------------------------------------\r\n");
for(Food x:menuSet)
out.write(x.name+" 价格:"+x.price+"\r\n");
out.write(createdate+"\r\n");
out.write("-------------------------------------------------------------\r\n");
out.close();
}catch(IOException a) {System.out.println("写入文件问题"+a.toString());}
for(Food x:menuSet)
System.out.println(x.name);
payframe.frame();
}
});
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static double getTotalPrice() {
double totalPrice = 0.0;
//Food food;
for (Food string : menuSet) {
//food = getFood(string);
totalPrice = totalPrice + string.getPrice();
}
System.out.println(totalPrice);
return totalPrice;
}
//使用 getFood方法获取形状类型的对象
public void setBg(){
((JPanel)this.getContentPane()).setOpaque(false);
ImageIcon img = new ImageIcon
("kfc.gif");
JLabel background = new JLabel(img);
this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
}
package Windows;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.*;
import javax.swing.JLabel;
public class Main_in extends JFrame{
public static void main(String[] args) {
HomePage t = new HomePage();
}
}
package Windows;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class JDBCUtil {
static String driverClass=null;
static String url=null;
static String user=null;
static String password= null;
static {//工具类中使用静态代码块,读取属性
try {
Properties properties = new Properties();
/**
* 使用类加载器读取src底下的资源文件;
*/
// TODO :: val is is null
//InputStream is =JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");//当点properties文件位于src中时,可用;
InputStream is =new FileInputStream("jdbc.properties"); //当点properties文件位于更目录下,即JDBC practice01下时,可用
properties.load(is);
driverClass=properties.getProperty("driverClass");
url=properties.getProperty("url");
user=properties.getProperty("user");
password=properties.getProperty("password");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static Connection getConn() {
Connection conn=null;
try {
System.out.println("a");
// Class.forName(driverClass); //可注释掉,已自动连接
conn = DriverManager.getConnection(url,user,password);
} catch (NullPointerException | SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
return conn;
}
public static void release(Connection conn, Statement createStatement, ResultSet rSet) {
closeConn(conn);
closecreateStatement(createStatement);
closerSet(rSet);
}
private static void closeConn(Connection conn) {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
conn = null;
}
}
private static void closecreateStatement(Statement createStatement) {
try {
if (createStatement != null) {
createStatement.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
createStatement = null;
}
}
private static void closerSet(ResultSet rSet) {
try {
if (rSet != null) {
rSet.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
rSet = null;
}
}
}
jdbc.properties文件
driverClass=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost/kfcsale
user=root
password= 123