📄 foodsetdao.java
字号:
package com.foodset.dao;
import java.sql.*;
import java.util.*;
import com.common.*;
import com.util.*;
import com.foodset.form.FoodSet;
import com.foodset.form.FoodSetSearchResult;
import com.foodset.rule.FoodSetRule;
import com.store.form.Store;
public class FoodsetDao {
public FoodsetDao() {
}
//插入套餐
public int inserFoodSetToDb(FoodSet model) {
int nRet = 0;
DBConnection dbc = null;
Connection conn = null;
Statement stmt = null;
String strSQL = null;
try {
dbc = new DBConnection();
conn = dbc.getDBConnection();
stmt = conn.createStatement();
String foodsetID = model.getFoodsetID();
String alias = model.getAlias();
String foodList = model.getFoodList();
float price = model.getPrice();
String descript = model.getDescript();
String weekNum = model.getWeekNum();
String weekday = model.getWeekday();
String foodImage = model.getFoodImage();
String storeID = model.getStoreID();
strSQL =
" INSERT foodset( foodsetID,alias,foodList,price,descript,weekNum,weekday,foodImage,storeID) values('" +
foodsetID + "','"+alias+"','"+foodList+"'," + price + ",'" + descript + "','" + weekNum + "','" +
weekday + "','"+foodImage+"','"+storeID+"')";
nRet = stmt.executeUpdate(strSQL);
}
catch (Exception e) {
nRet = -1;
e.printStackTrace();
System.out.println("\n" + e.toString() + "插入套餐" + strSQL); /////错误处理!
}
finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
dbc.closeDBConnection(conn);
}
}
catch (Exception ex) {}
}
return nRet;
}
public int deleteFootSet(String foodsetID,String storeID)
{
int nRet = 0;
DBConnection dbc = null;
Connection conn = null;
Statement stmt = null;
String strSQL = null;
try {
dbc = new DBConnection();
conn = dbc.getDBConnection();
stmt = conn.createStatement();
strSQL = " delete from foodset where foodsetID='" + foodsetID + "' and storeID='"+storeID+"'";
nRet = stmt.executeUpdate(strSQL);
}
catch (Exception e) {
nRet = -1;
e.printStackTrace();
System.out.println("\n" + e.toString() + "删除套餐" + strSQL); /////错误处理!
}
finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
dbc.closeDBConnection(conn);
}
}
catch (Exception ex) {}
}
return nRet;
}
public int updateFoodSet(FoodSet model) {
int nRet = 0;
DBConnection dbc = null;
Connection conn = null;
Statement stmt = null;
String strSQL = null;
try {
dbc = new DBConnection();
conn = dbc.getDBConnection();
stmt = conn.createStatement();
String foodsetID = model.getFoodsetID();
String alias = model.getAlias();
String foodList = model.getFoodList();
float price = model.getPrice();
String descript = model.getDescript();
String weekNum = model.getWeekNum();
String weekday = model.getWeekday();
String foodImage = model.getFoodImage();
strSQL =" update foodset set alias='"+alias+"',foodList='"+foodList+"',price="+price+",descript='"+descript+
"',weekNum='"+weekNum+"',weekday='"+weekday + "',foodImage='"+foodImage+"' where foodsetID='"+foodsetID+"'";
nRet = stmt.executeUpdate(strSQL);
}
catch (Exception e) {
nRet = -1;
e.printStackTrace();
System.out.println("\n" + e.toString() + "更新套餐" + strSQL); /////错误处理!
}
finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
dbc.closeDBConnection(conn);
}
}
catch (Exception ex) {}
}
return nRet;
}
public List getAllSetList()
{
int nRet = 0;
List foodsetList = new ArrayList();
DBConnection dbc = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String strSQL = null;
try {
dbc = new DBConnection();
conn = dbc.getDBConnection();
stmt = conn.createStatement();
strSQL = "select * from v_foodset_store Order by weekday";
rs = stmt.executeQuery(strSQL);
while(rs.next())
{
FoodSet set = new FoodSet();
set.setFoodsetID(rs.getString("foodsetID"));
set.setAlias(rs.getString("alias"));
set.setFoodList(rs.getString("foodList"));
set.setPrice(rs.getFloat("price"));
set.setDescript(rs.getString("descript"));
set.setWeekNum(rs.getString("weekNum"));
set.setWeekday(rs.getString("weekday"));
set.setFoodImage(rs.getString("foodImage"));
set.setStoreID(rs.getString("storeID"));
set.setStoreName(rs.getString("storeName"));
foodsetList.add(set);
}
}
catch (Exception e) {
nRet = -1;
e.printStackTrace();
System.out.println("\n" + e.toString() + "更新套餐" + strSQL); /////错误处理!
}
finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
dbc.closeDBConnection(conn);
}
}
catch (Exception ex) {}
}
return foodsetList;
}
public List getAllSetList(String storeID)
{
int nRet = 0;
List foodsetList = new ArrayList();
DBConnection dbc = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String strSQL = null;
try {
dbc = new DBConnection();
conn = dbc.getDBConnection();
stmt = conn.createStatement();
strSQL = "select * from v_foodset_store where storeID='"+storeID+"' Order by weekday";
rs = stmt.executeQuery(strSQL);
while(rs.next())
{
FoodSet set = new FoodSet();
set.setFoodsetID(rs.getString("foodsetID"));
set.setAlias(rs.getString("alias"));
set.setFoodList(rs.getString("foodList"));
set.setPrice(rs.getFloat("price"));
set.setDescript(rs.getString("descript"));
set.setWeekNum(rs.getString("weekNum"));
set.setWeekday(rs.getString("weekday"));
set.setFoodImage(rs.getString("foodImage"));
set.setStoreID(rs.getString("storeID"));
set.setStoreName(rs.getString("storeName"));
foodsetList.add(set);
}
}
catch (Exception e) {
nRet = -1;
e.printStackTrace();
System.out.println("\n" + e.toString() + "更新套餐" + strSQL); /////错误处理!
}
finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
dbc.closeDBConnection(conn);
}
}
catch (Exception ex) {}
}
return foodsetList;
}
public FoodSet getOneFoodSet(String foodsetID,String storeID)
{
DBConnection dbc = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String strSQL = null;
FoodSet set = new FoodSet();
try {
dbc = new DBConnection();
conn = dbc.getDBConnection();
stmt = conn.createStatement();
strSQL = "select * from v_foodset_store where foodsetID='"+foodsetID+"' and storeID='"+storeID+"'";
rs = stmt.executeQuery(strSQL);
if(rs.next())
{
set.setFoodsetID(rs.getString("foodsetID"));
set.setAlias(rs.getString("alias"));
set.setFoodList(rs.getString("foodList"));
set.setPrice(rs.getFloat("price"));
set.setDescript(rs.getString("descript"));
set.setWeekNum(rs.getString("weekNum"));
set.setWeekday(rs.getString("weekday"));
set.setFoodImage(rs.getString("foodImage"));
set.setStoreID(rs.getString("storeID"));
set.setStoreName(rs.getString("storeName"));
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println("\n" + e.toString() + "更新套餐" + strSQL); /////错误处理!
}
finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
dbc.closeDBConnection(conn);
}
}
catch (Exception ex) {}
}
return set;
}
public FoodSet getOneFoodSet(String foodsetID)
{
DBConnection dbc = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String strSQL = null;
FoodSet set = new FoodSet();
try {
dbc = new DBConnection();
conn = dbc.getDBConnection();
stmt = conn.createStatement();
strSQL = "select * from v_foodset_store where foodsetID='"+foodsetID+"'";
rs = stmt.executeQuery(strSQL);
if(rs.next())
{
set.setFoodsetID(rs.getString("foodsetID"));
set.setAlias(rs.getString("alias"));
set.setFoodList(rs.getString("foodList"));
set.setPrice(rs.getFloat("price"));
set.setDescript(rs.getString("descript"));
set.setWeekNum(rs.getString("weekNum"));
set.setWeekday(rs.getString("weekday"));
set.setFoodImage(rs.getString("foodImage"));
set.setStoreID(rs.getString("storeID"));
set.setStoreName(rs.getString("storeName"));
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println("\n" + e.toString() + "更新套餐" + strSQL); /////错误处理!
}
finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
dbc.closeDBConnection(conn);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -