主頁 > 後端開發 > JDBC基本內容——19資料庫復習備考

JDBC基本內容——19資料庫復習備考

2021-01-06 06:21:19 後端開發

ZUCC?BK阿碼農?2021年1月5日

PS.
(1)為應試準備的博客,不重要僅代表不太考的內容,不是JDBC里不重要,
(2)下面有一些騙分小技巧

1. JDBC代碼應試

(0)加載驅動程式、獲取資料庫連接(不重要

(1)初始化

  • 創建conn連接,一般寫在try前,初始定義空,
java.sql.Connection conn =null;
  • 設計JDBC肯定有OOP(面向物件)的內容,比如:
  • 我們的函式可以使用implement(介面)
  • 也肯定會涉及@Override重寫
  • 不重要
  • 短學期會用

(2)進入try

  • 獲取conn物體的連接
conn=DBUtil.getConnection();

(3)方法一:Statement(個人常用:查詢陳述句、遍歷輸出)

//定義sql陳述句
String sql="select 列名 from 表名 where 列A="+列A的內容;
//創建Statement
java.sql.Statement st=conn.createStatement();
//定義rs資料佇列,execute執行Statement,結果存在rs里
java.sql.ResultSet rs=st.executeQuery(sql);
//最后務必關閉Statement以及rs資料佇列
st.close();
rs.close();
  • rs一般會執行rs.next()判斷是否查詢到有用資訊,再進行刪、改
if(rs.next()){
      //查詢有結果,先關閉此次查詢
       rs.close();
      st.close();
      //進行其他的sql操作,比如對找到的行進行UPDATE、DELETE
      //新建Statement或Preparedstatement,進行下一次的sql操作
}else{
      //查詢結果為空
      rs.close();
      st.close();
}
  • rs也能通過rs.next()進行遍歷,將查詢出來的值一一列印或寫進某處
while(rs.next()){//查詢有結果,進行操作,直到最后結果操作完畢后退出
      //對rs所指的內容進行操作
}

(4)方法二:PreparedStatement(個人常用:增加陳述句、洗掉陳述句、更新陳述句,查詢陳述句也可以)

//定義sql陳述句,問號"?"是PreparedStatement的優勢,下文會提及
//列1是更新列,列2是判斷列
String sql="update 表名 set 列名1=? where 列名2= ?";
//創建PreparedStatement
java.sql.PreparedStatement pst=conn.prepareStatement(sql);
//pst.setObject(第n個問號,資料值);
//setObect:根據問號處資料的型別,可以是setInt、setDouble、setString等
pst.setString(1, 第一個問號的值);
pst.setInt(2, 第一個問號的值);
//執行操作
pst.execute();
//最后務必關閉PreparedStatement
pst.close();

(5)try內容結束,緊跟catch與final(不重要)

//catch抓的SQLException是SQL錯誤,有錯誤會報錯并列印路徑(監督try的內容)
catch (SQLException e) {
	e.printStackTrace();
	try {
              //提交事務(不重要)
	      conn.commit();
	} catch (SQLException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	throw new DbException(e);
}
 //最后的操作,關閉資料庫
finally {
	if (conn!=null) {
		try {
		//關閉資料庫
		      conn.close();
		} catch (SQLException e2) {
		      // TODO Auto-generated catch block
		      e2.printStackTrace();
            	}
      }
}

2. Statement和Preparedstatement區別

(1)區別:

  • Statement用于執行靜態SQL陳述句,在執行時,必須指定一個事先準備好的SQL陳述句
  • PreparedStatement繼承自Statement,都為介面
  • PreparedStatement可以使用占位符(即問號?),是預編譯的,批處理比Statement效率高
  • PreparedStatement可以減少編譯次數,來提高資料庫性能
  • 三種方法 execute、 executeQuery 和 executeUpdate 已被更改以使之不再需要引數(這些方法的 Statement 形式:‘接受 SQL 陳述句引數的形式’,不應該用于 PreparedStatement 物件)

(2)百度百科有一句話:

(不相信可以點傳送門,老翁也說過好像)

  • 有人主張,在JDBC應用中,如果你已經是稍有水平開發者,你就應該始終以PreparedStatement代替Statement!也就是說,在任何時候都不要使用Statement

(3)個人解讀:

PreparedStatement比Statement:

  • 更高效(預編譯、重復多次執行)
  • 方便
  • 代碼更易讀(SetObject方法比寫大長段的Sql字串好)

(4)他人見解:

  • JDBC:深入理解PreparedStatement和Statement
  • Statement和PrepareStatement的區別詳解
  • statement和preparestatement的區別

3. 關于騙分

(1)程式填空題如果有的話,在所難免會有初始化,都是亙古不變的,比如:

//創建conn
java.sql.Connection conn =null;
//conn獲取連接
conn=DBUtil.getConnection();
//創建Statement或Preparedstatement
java.sql.Statement st=conn.createStatement();
java.sql.PreparedStatement pst=conn.prepareStatement(sql);
//Preparedstatement操作執行
pst.execute();
//關閉各種
rs.close();//結果集關閉
st.close();//Statement關閉
pst.close();//Preparedstatement關閉
conn.close();//連接關閉

(2)個人覺得Preparedstatement方便,sql直接寫問號

  • Statement涉及ResultSet結果集
  • Preparedstatement在后面setObject(setInt、setString、setDouble等),簡單易懂

(3)開頭初始化創建和結尾關閉操作不拿分那可真是浪費了

4. 實戰嘗試

隨便拉了些原始碼,可以參考整體的代碼環境,多理解才能掌握,死記硬背不咋行哦

(1)物體類方法重寫(最下面是ICMD介面代碼+方法注釋):

package src.cn.edu.zucc.waimai.comtrol.example;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import src.cn.edu.zucc.waimai.itf.ICMD;
import src.cn.edu.zucc.waimai.model.BeanCMD;
import src.cn.edu.zucc.waimai.model.BeanOrder;
import src.cn.edu.zucc.waimai.model.BeanQs;
import src.cn.edu.zucc.waimai.model.BeanQsbill;
import src.cn.edu.zucc.waimai.model.BeanSj;
import src.cn.edu.zucc.waimai.model.BeanSjFL;
import src.cn.edu.zucc.waimai.model.BeanSjMJ;
import src.cn.edu.zucc.waimai.model.BeanSjYHQ;
import src.cn.edu.zucc.waimai.model.BeanSp;
import src.cn.edu.zucc.waimai.model.BeanUser;
import src.cn.edu.zucc.waimai.model.BeanUserAdd;
import src.cn.edu.zucc.waimai.util.BaseException;
import src.cn.edu.zucc.waimai.util.BusinessException;
import src.cn.edu.zucc.waimai.util.DBUtil;
import src.cn.edu.zucc.waimai.util.DbException;

public class CMDManager implements ICMD {
	@Override
	public void QSJD(BeanQs qs,BeanOrder order) throws BaseException{
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from order_data where order_id="+order.getOrder_id();//查找訂單
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {	
				rs.close();
				st.close();
				sql="update order_data set qs_id=?,order_state=? where order_id=?";
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setInt(1,qs.getQs_id());
				pst.setString(2, "派送中");
				pst.setInt(3, order.getOrder_id());
				pst.execute();
				pst.close();
			}
			else {
				rs.close();
				st.close();
				throw new BusinessException("該訂單不存在");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void modifyOrder(BeanOrder order,String state) throws BaseException{
		if(state.equals("")) {
			throw new BusinessException("修改狀態不能為空!");
		}
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from order_data where order_id="+order.getOrder_id();//查找訂單
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="update order_data set order_state=? where order_id= ? ";//更新操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setString(1, state);
				pst.setInt(2, order.getOrder_id());
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("該訂單不存在");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public List<BeanOrder> loadAllOrder()throws BaseException{
		 List<BeanOrder> result=new ArrayList<BeanOrder>();
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select *"
					+ " from order_data order by order_id";
			java.sql.PreparedStatement pst= conn.prepareStatement(sql);
			java.sql.ResultSet rs=pst.executeQuery();
			while(rs.next()) {
				BeanOrder p=new BeanOrder();
				p.setOrder_id(rs.getInt(1));
				p.setSj_id(rs.getInt(2));
				p.setUser_id(rs.getInt(3));
				p.setQs_id(rs.getInt(4));
				p.setOrder_origin_money(rs.getFloat(5));
				p.setOrder_final_money(rs.getFloat(6));
				p.setMj_id(rs.getInt(7));
				p.setYouhuiquan_id(rs.getInt(8));
				p.setOrder_set_time(rs.getTimestamp(9));
				p.setOrder_set_arrive_time(rs.getTimestamp(10));
				p.setUser_address_id(rs.getInt(11));
				p.setOrder_state(rs.getString(12));
				result.add(p);
			}
			rs.close();
			pst.close();
			return result;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Override
	public void modifyQS(BeanQs qs,String name,String grade) throws BaseException{
		if(name.equals("")) {
			throw new BusinessException("騎手姓名不能為空!");
		}
		if(grade.equals("")) {
			throw new BusinessException("騎手等級不能為空!");
		}
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from qs_data where qs_id="+qs.getQs_id();//查找騎手
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				
				sql="update qs_data set qs_name=?,qs_grade=? where qs_id= ? ";//更新操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setString(1, name);
				pst.setString(2, grade);
				pst.setInt(3, qs.getQs_id());
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("該騎手已不存在");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void deleteQS(BeanQs qs) throws BaseException{
		java.sql.Connection conn =null;
		int a=1;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from qs_data where qs_id="+qs.getQs_id()+"qs_name="+qs.getQs_name();//檢查是否存在商品
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="delete from qs_data where qs_id=?";//洗掉操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setInt(1, qs.getQs_id());
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("該騎手已經不存在");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void regQS(String name,String grade)throws BaseException{
		if(name.equals("")) {
			throw new BusinessException("騎手姓名不能為空!");
		}
		if(grade.equals("")) {
			throw new BusinessException("騎手等級不能為空!");
		}
		java.sql.Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			String sql="insert into qs_data(qs_name,qs_join_date,qs_grade) values(?,now(),?)";
			java.sql.PreparedStatement pst=conn.prepareStatement(sql);
			pst=conn.prepareStatement(sql);
			pst.setString(1, name);
			pst.setString(2, grade);
			pst.execute();
			pst.close();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if(conn!=null)
				try {
					conn.close();
				}catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}
	@Override
	public void modifyMJ(BeanSjMJ sjmj,String top,String count,String ifmj) throws BaseException{
		if(top.equals("")) {
			throw new BusinessException("滿減金額不能為空!");
		}
		if(count.equals("")) {
			throw new BusinessException("優惠金額不能為空!");
		}
		if(ifmj.equals("")) {
			throw new BusinessException("是否與優惠券疊加不能為空!");
		}
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from sj_manjian where mj_id="+sjmj.getMj_id();//查找滿減
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				
				sql="update sj_manjian set mj_top_money=?,mj_discount_money=?,if_add_youhuiquan=? where mj_id= ? ";//更新操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setFloat(1, Float.parseFloat(top));
				pst.setFloat(2, Float.parseFloat(count));
				pst.setInt(3,Integer.parseInt(ifmj));
				pst.setInt(4,sjmj.getMj_id());
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("該商家分欄已經不存在該商品了");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void deleteMJ(BeanSjMJ sjmj) throws BaseException{
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from sj_manjian where mj_id="+sjmj.getMj_id();//檢查是否存在商品
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="delete from sj_manjian where mj_id=?";//洗掉操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setInt(1, sjmj.getMj_id());
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("已經不存在該滿減政策");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void regMJ(BeanSj sj,String top,String count,String ifmj)throws BaseException{
		if(top.equals("")) {
			throw new BusinessException("滿減金額不能為空!");
		}
		if(count.equals("")) {
			throw new BusinessException("優惠金額不能為空!");
		}
		if(ifmj.equals("")) {
			throw new BusinessException("是否與優惠券疊加不能為空!");
		}
		java.sql.Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			String sql="insert into sj_manjian(sj_id,mj_top_money,"
					+ "mj_discount_money,if_add_youhuiquan) values(?,?,?,?)";
			java.sql.PreparedStatement pst=conn.prepareStatement(sql);
			pst=conn.prepareStatement(sql);
			pst.setInt(1, sj.getSj_id());
			pst.setFloat(2, Float.parseFloat(top));
			pst.setFloat(3, Float.parseFloat(count));
			pst.setInt(4, Integer.parseInt(ifmj));
			pst.execute();
			pst.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if(conn!=null)
				try {
					conn.close();
				}catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}
	@Override
	public void modifyYHQ(BeanSjYHQ sjyhq,String youhui_money,String jidan,String days) throws BaseException{
		if(youhui_money.equals("")) {
			throw new BusinessException("優惠金額不能為空!");
		}
		if(jidan.equals("")) {
			throw new BusinessException("集單要求不能為空!");
		}
		if(days.equals("")) {
			throw new BusinessException("增加天數不能為空!");
		}
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from sj_youhuiquan where youhuiquan_id="+sjyhq.getYouhuiquan_id();//查找優惠券
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				
				Timestamp longend =new Timestamp(0);
				sql="select ADDDATE(?,interval ? day)";
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setTimestamp(1, sjyhq.getYouhuiquan_end_time());
				pst.setInt(2,Integer.parseInt(days));
				rs=pst.executeQuery();
				while(rs.next())
					longend=rs.getTimestamp(1);
				pst.close();
				rs.close();
				
				sql="update sj_youhuiquan set youhui_money=?,jidan_least_count=?,youhuiquan_end_time=? where youhuiquan_id= ? ";//更新操作
				pst=conn.prepareStatement(sql);
				pst.setFloat(1, Float.parseFloat(youhui_money));
				pst.setInt(2, Integer.parseInt(jidan));
				pst.setTimestamp(3, longend);
				pst.setInt(4, sjyhq.getYouhuiquan_id());
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("該商家分欄已經不存在該商品了");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void deleteYHQ(BeanSjYHQ sjyhq) throws BaseException{
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from sj_youhuiquan where youhuiquan_id="+sjyhq.getYouhuiquan_id();//檢查是否存在商品
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="delete from sj_youhuiquan where youhuiquan_id=?";//洗掉操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setInt(1, sjyhq.getYouhuiquan_id());
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("已經不存在該優惠券");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void regYHQ(BeanSj sj,String youhui_money,String jidan,String days)throws BaseException{
		if(youhui_money.equals("")) {
			throw new BusinessException("優惠金額不能為空!");
		}
		if(jidan.equals("")) {
			throw new BusinessException("集單要求不能為空!");
		}
		if(days.equals("")) {
			throw new BusinessException("活動天數不能為空!");
		}
		java.sql.Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			Timestamp begin=new Timestamp(0);
			Timestamp end=new Timestamp(0);
			String sql="select ADDDATE(now(),interval 0 day)";
			java.sql.PreparedStatement pst=conn.prepareStatement(sql);
			java.sql.ResultSet rs=pst.executeQuery();
			while(rs.next())
				begin=rs.getTimestamp(1);
			pst.close();
			rs.close();
			
			sql="select ADDDATE(now(),interval ? day)";
			pst=conn.prepareStatement(sql);
			pst.setInt(1,Integer.parseInt(days));
			rs=pst.executeQuery();
			while(rs.next())
				end=rs.getTimestamp(1);
			pst.close();
			rs.close();
			
			sql="insert into sj_youhuiquan(sj_id,youhui_money,"
					+ "jidan_least_count,youhuiquan_begin_time,youhuiquan_end_time) values(?,?,?,?,?)";
			pst=conn.prepareStatement(sql);
			pst.setInt(1, sj.getSj_id());
			pst.setFloat(2, Float.parseFloat(youhui_money));
			pst.setInt(3, Integer.parseInt(jidan));
			pst.setTimestamp(4, begin);
			pst.setTimestamp(5, end);
			pst.execute();
			pst.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if(conn!=null)
				try {
					conn.close();
				}catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}
	@Override
	public void modifySP(BeanSp sp,String name,String price,String left) throws BaseException{
		java.sql.Connection conn =null;
		try {
			int sp_id=sp.getSp_id();
			conn=DBUtil.getConnection();
			String sql="select * from sp_data where sp_id="+sp_id;//查找商品
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="update sp_data set sp_name=?,sp_price=?,sp_left_count=? where sp_id= ? ";//更新操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setString(1, name);
				pst.setFloat(2, Float.parseFloat(price));
				pst.setInt(3, Integer.parseInt(left));
				pst.setInt(4, sp_id);
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("該商家分欄已經不存在該商品了");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void deleteSP(BeanSp sp) throws BaseException{
		java.sql.Connection conn =null;
		try {
			int sp_id=sp.getSp_id();
			int fl_id=sp.getFl_id();
			conn=DBUtil.getConnection();
			String sql="select * from sp_data where sp_id="+sp_id;//檢查是否存在商品
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="delete from sp_data where sp_id=?";//洗掉操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setInt(1, sp_id);
				pst.execute();
				pst.close();
				sql="update sp_leibie set sp_count=sp_count-1 where leibie_id=?";//
				pst=conn.prepareStatement(sql);
				pst.setInt(1, fl_id);
				pst.execute();
				pst.close();
				
			}else {
				rs.close();
				st.close();
				throw new BusinessException("已經不存在該商品");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void modifySjFL(BeanSjFL sjfl,String name) throws BaseException{
		java.sql.Connection conn =null;
		try {
			int sjfl_id=sjfl.getLeibie_id();
			conn=DBUtil.getConnection();
			String sql="select * from sp_leibie where leibie_id="+sjfl_id;//查找商家類別
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="update sp_leibie set leibie_name=? where leibie_id= ? ";//更新操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setString(1, name);
				pst.setInt(2, sjfl_id);
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("該商家已經不存在該分欄");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void deleteSjFL(BeanSjFL sjfl) throws BaseException{
		java.sql.Connection conn =null;
		try {
			int sjfl_id=sjfl.getLeibie_id();
			conn=DBUtil.getConnection();
			String sql="select * from sp_data where sp_belong_leibie_id="+sjfl_id;//檢查是否存在商品
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			while(rs.next()) {
				rs.close();
				st.close();
				throw new BusinessException("該商家分欄中仍存在商品,不能直接洗掉");
			}
			rs.close();
			
			sql="select * from sp_leibie where leibie_id="+sjfl_id;//查找商家分欄
			rs=st.executeQuery(sql);
			if(rs.next()&&sjfl.getLeibie_sp_count()==0) {
				rs.close();
				st.close();
				sql="delete from sp_leibie where leibie_id=?";//洗掉操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setInt(1, sjfl_id);
				pst.execute();
				pst.close();
				
			}else {
				if(sjfl.getLeibie_sp_count()!=0) {
					rs.close();
					st.close();
					throw new BusinessException("該商家分欄中商品數不為0,請檢查");
				}else {
					rs.close();
					st.close();
					throw new BusinessException("已經不存在該商家");
				}
				
			}
			
//			conn.commit();//結束事務
		} 
//		catch (BaseException e) {
//			try {
//				conn.rollback();
//			} catch (SQLException e1) {
//				// TODO Auto-generated catch block
//				e1.printStackTrace();
//			}
//		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void modifySj(BeanSj sj,String name,String xinji) throws BaseException{
		java.sql.Connection conn =null;
		try {
			int sj_id=sj.getSj_id();
			conn=DBUtil.getConnection();
			String sql="select * from sj_data where sj_id="+sj_id;//查找商家
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="update sj_data set sj_name=?,sj_xinji=? where sj_id= ? ";//更新操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setString(1, name);
				pst.setInt(2, Integer.parseInt(xinji));
				pst.setInt(3, sj_id);
				pst.execute();
				pst.close();
			}else {
				rs.close();
				st.close();
				throw new BusinessException("已經不存在該商家");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
	}
	@Override
	public void deleteSj(BeanSj sj) throws BaseException {
		java.sql.Connection conn =null;
		try {
			int sj_id=sj.getSj_id();
			conn=DBUtil.getConnection();
//			conn.setAutoCommit(false);//開啟事務
			String sql="select * from sp_leibie where sj_id="+sj_id;//檢查是否存在分欄
			java.sql.Statement st=conn.createStatement();
			java.sql.ResultSet rs=st.executeQuery(sql);
			while(rs.next()) {
				rs.close();
				st.close();
				throw new BusinessException("該商家仍存在分欄,不能直接洗掉");
			}
			rs.close();
			
			sql="select * from sj_data where sj_id="+sj_id;//查找商家
			rs=st.executeQuery(sql);
			if(rs.next()) {
				rs.close();
				st.close();
				sql="delete from sj_data where sj_id=?";//洗掉操作
				java.sql.PreparedStatement pst=conn.prepareStatement(sql);
				pst.setInt(1, sj_id);
				pst.execute();
				pst.close();
				
			}else {
				rs.close();
				st.close();
				throw new BusinessException("已經不存在該商家");
			}
			
//			conn.commit();//結束事務
		} 
//		catch (BaseException e) {
//			try {
//				conn.rollback();
//			} catch (SQLException e1) {
//				// TODO Auto-generated catch block
//				e1.printStackTrace();
//			}
//		}
		catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.commit();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
			}
		}
		

	}

	@Override
	public List<BeanUserAdd> loadAllYHadd(BeanUser user)throws BaseException{
		List<BeanUserAdd> result=new ArrayList<BeanUserAdd>();
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select user_id,user_province,user_city,user_area,user_address_detail,user_ad_name,user_ad_phonenum"
					+ " from user_address where user_id=? order by user_address_id";
			java.sql.PreparedStatement pst= conn.prepareStatement(sql);
			pst.setInt(1, user.getUser_id());
			java.sql.ResultSet rs=pst.executeQuery();
			while(rs.next()) {
				BeanUserAdd p=new BeanUserAdd();
				p.setUser_id(rs.getInt(1));
				p.setUser_province(rs.getString(2));
				p.setUser_city(rs.getString(3));
				p.setUser_area(rs.getString(4));
				p.setUser_add_detail(rs.getString(5));
				p.setUser_add_name(rs.getString(6));
				p.setUser_add_phonenum(rs.getString(7));
				result.add(p);
			}
			rs.close();
			pst.close();
			return result;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Override
	public BeanUser reg(String username,int usersex, String pwd,String pwd2,String userphonenum,
			String usere_mail,String usercity) throws BaseException{
		if(username.equals("")) {
			throw new BusinessException("用戶名不能為空!");
		}
		if(usersex!=0 && usersex!=1) {
			throw new BusinessException("性別請輸入0(女性)或1(男性)!");
		}
		if(pwd.equals("")) {
			throw new BusinessException("密碼不能為空!");
		}
		if(pwd2.equals("")) {
			throw new BusinessException("請第二次輸入密碼!");
		}
		if(!(pwd.equals(pwd2))) {
			throw new BusinessException("兩次密碼不一致!");
		}
		if(userphonenum.equals("")) {
			throw new BusinessException("手機號碼不能為空!");
		}
		if(usere_mail.equals("")) {
			throw new BusinessException("郵箱不能為空!");
		}
		if(usercity.equals("")) {
			throw new BusinessException("所在城市不能為空!");
		}
		java.sql.Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from user_data where user_name=?";
			java.sql.PreparedStatement pst=conn.prepareStatement(sql);
			pst.setString(1,username);
			java.sql.ResultSet rs=pst.executeQuery();
			if(rs.next())throw new BusinessException("姓名已存在!");
			rs.close();
			pst.close();
			sql="insert into user_data(user_name,user_sex,user_pwd,user_phonenum,"
					+ "user_email,user_city,user_register_time) values(?,?,?,?,?,?,?)";
			pst=conn.prepareStatement(sql);
			pst.setString(1, username);
			pst.setInt(2, usersex);
			pst.setString(3, pwd);
			pst.setString(4, userphonenum);
			pst.setString(5, usere_mail);
			pst.setString(6, usercity);
			pst.setTimestamp(7, new java.sql.Timestamp(System.currentTimeMillis()));
			pst.execute();
			pst.close();
			BeanUser bu=new BeanUser();
			bu.setUser_name(username);
			bu.setUser_sex(usersex);
			bu.setUser_pwd(pwd);
			bu.setUser_phonenum(userphonenum);
			bu.setUser_email(usere_mail);
			bu.setUser_city(usercity);
			bu.setUser_register_time(new java.sql.Timestamp(System.currentTimeMillis()));
			bu.setUser_vip_end_time(null);
			return bu;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if(conn!=null)
				try {
					conn.close();
				}catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}
	@Override
	public List<BeanUser> loadAllYH()throws BaseException{
		List<BeanUser> result=new ArrayList<BeanUser>();
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select user_id,user_name,user_sex,user_pwd,user_phonenum,user_email,user_city,user_register_time,user_vip_end_time"
					+ " from user_data";
			java.sql.PreparedStatement pst= conn.prepareStatement(sql);
			
			java.sql.ResultSet rs=pst.executeQuery();
			while(rs.next()) {
				BeanUser p=new BeanUser();
				p.setUser_id(rs.getInt(1));
				p.setUser_name(rs.getString(2));
				p.setUser_sex(rs.getInt(3));
				p.setUser_pwd(rs.getString(4));
				p.setUser_phonenum(rs.getString(5));
				p.setUser_email(rs.getString(6));
				p.setUser_city(rs.getString(7));
				p.setUser_register_time(rs.getTimestamp(8));
				p.setUser_vip_end_time(rs.getTimestamp(9));
				result.add(p);
			}
			rs.close();
			pst.close();
			return result;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Override
	public List<BeanQs> loadAllQS()throws BaseException{
		List<BeanQs> result=new ArrayList<BeanQs>();
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from qs_data";
			java.sql.PreparedStatement pst= conn.prepareStatement(sql);
			java.sql.ResultSet rs=pst.executeQuery();
			while(rs.next()) {
				BeanQs p=new BeanQs();
				p.setQs_id(rs.getInt(1));
				p.setQs_name(rs.getString(2));
				p.setQs_join_date(rs.getTimestamp(3));
				p.setQs_grade(rs.getString(4));
				result.add(p);
			}
			rs.close();
			pst.close();
			return result;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	@Override
	public List<BeanQsbill> loadAllQSbill(BeanQs qs)throws BaseException{
		List<BeanQsbill> result=new ArrayList<BeanQsbill>();
		java.sql.Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from qs_bill"
					+ " where qs_id = ?";
			java.sql.PreparedStatement pst= conn.prepareStatement(sql);
			pst.setInt(1,qs.getQs_id());
			java.sql.ResultSet rs=pst.executeQuery();
			while(rs.next()) {
				BeanQsbill p=new BeanQsbill();
				p.setQs_id(rs.getInt(1));
				p.setOrder_id(rs.getInt(2));
				p.setQs_getmoney_time(rs.getTimestamp(3));
				p.setQs_getmoney(rs.getFloat(4));
				p.setSp_evaluate_qsxinji(rs.getInt(5));
				result.add(p);
			}
			rs.close();
			pst.close();
			return result;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	@Override
	public BeanCMD login(String username,String pwd)throws BaseException{
		if(username.equals("")) {
			throw new BusinessException("用戶名為空!");
		}
		if(pwd.equals("")) {
			throw new BusinessException("密碼不能為空!");
		}
		java.sql.Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			String sql="select cmd_id,cmd_name,cmd_pwd from cmd_data where cmd_name=? and cmd_pwd=?";
			java.sql.PreparedStatement pst= conn.prepareStatement(sql);
			pst.setString(1, username);
			pst.setString(2, pwd);
			java.sql.ResultSet rs= pst.executeQuery();
			if(rs.next()) {
				BeanCMD bu=new BeanCMD();
				bu.setCMD_id(rs.getInt(1));//獲取用戶編號
				bu.setCMD_name(username);
				bu.setCMD_pwd(pwd);
				pst.close();
				rs.close();
				return bu;
			}else {
				throw new BusinessException("賬號或密碼錯誤");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if(conn!=null) {
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	@Override
	public List<BeanCMD> loadAll()throws BaseException{
		List<BeanCMD> result=new ArrayList<BeanCMD>();
		java.sql.Connection conn =null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from cmd_data";
			java.sql.PreparedStatement pst= conn.prepareStatement(sql);
			java.sql.ResultSet rs=pst.executeQuery();
			while(rs.next()) {
				BeanCMD p=new BeanCMD();
				p.setCMD_id(rs.getInt(1));
				p.setCMD_name(rs.getString(2));
				p.setCMD_pwd(rs.getString(3));
				result.add(p);
			}
			rs.close();
			pst.close();
			return result;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if (conn!=null) {
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	@Override
	public BeanCMD reg(String cmdusername,String cmdpwd,String username,String pwd)throws BaseException{
		if(cmdusername.equals("")) {
			throw new BusinessException("管理員名為空!");
		}
		if(cmdpwd.equals("")) {
			throw new BusinessException("管理員密碼不能為空!");
		}
		if(username.equals("")) {
			throw new BusinessException("新管理員名為空!");
		}
		if(pwd.equals("")) {
			throw new BusinessException("新管理員密碼不能為空!");
		}
		java.sql.Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from cmd_data where cmd_name=?";
			java.sql.PreparedStatement pst=conn.prepareStatement(sql);
			pst.setString(1,username);
			java.sql.ResultSet rs=pst.executeQuery();
			if(rs.next()) {
				rs.close();
				pst.close();
				throw new BusinessException("管理員姓名已存在!");
			}
			rs.close();
			pst.close();
			sql="select cmd_pwd from cmd_data where cmd_name=?";
			pst=conn.prepareStatement(sql);
			pst.setString(1, cmdusername);
			rs=pst.executeQuery();
			if(rs.next()) {
				if(!cmdpwd.equals(rs.getString(1))) {
					rs.close();
					pst.close();
					throw new BusinessException("管理員密碼認證失敗!");
				}
			}else {
				rs.close();
				pst.close();
				throw new BusinessException("管理員賬號不存在");
			}
			rs.close();
			pst.close();
			
			sql="insert into cmd_data(cmd_name,cmd_pwd) values(?,?)";
			pst=conn.prepareStatement(sql);
			pst.setString(1, username);
			pst.setString(2, pwd);
			pst.execute();
			pst.close();
			BeanCMD bu=new BeanCMD();
			bu.setCMD_name(username);
			bu.setCMD_pwd(pwd);
			return bu;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if(conn!=null)
				try {
					conn.close();
				}catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}
	@Override
	public BeanCMD modify(String cmdusername,String cmdpwd,String username,String pwd)throws BaseException{
		if(cmdusername.equals("")) {
			throw new BusinessException("管理員名為空!");
		}
		if(cmdpwd.equals("")) {
			throw new BusinessException("管理員密碼不能為空!");
		}
		if(username.equals("")) {
			throw new BusinessException("新管理員名為空!");
		}
		if(pwd.equals("")) {
			throw new BusinessException("新管理員密碼不能為空!");
		}
		java.sql.Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			String sql="select * from cmd_data where cmd_name=?";
			java.sql.PreparedStatement pst=conn.prepareStatement(sql);
			pst.setString(1,username);
			java.sql.ResultSet rs=pst.executeQuery();
			if(rs.next()&&(!rs.getString(2).equals(cmdusername))) {
				rs.close();
				pst.close();
				throw new BusinessException("管理員姓名已存在!");
			}
			rs.close();
			pst.close();
			sql="select cmd_pwd from cmd_data where cmd_name=?";
			pst=conn.prepareStatement(sql);
			pst.setString(1, cmdusername);
			rs=pst.executeQuery();
			if(rs.next()) {
				if(!cmdpwd.equals(rs.getString(1))) {
					rs.close();
					pst.close();
					throw new BusinessException("管理員密碼認證失敗!");
				}
			}else {
				rs.close();
				pst.close();
				throw new BusinessException("管理員賬號不存在");
			}
			rs.close();
			pst.close();
			
			sql="update cmd_data set cmd_name=?,cmd_pwd=? where cmd_name=?";
			pst=conn.prepareStatement(sql);
			pst.setString(1, username);
			pst.setString(2, pwd);
			pst.setString(3, cmdusername);
			pst.execute();
			pst.close();
			BeanCMD bu=new BeanCMD();
			bu.setCMD_name(username);
			bu.setCMD_pwd(pwd);
			return bu;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new DbException(e);
		} finally {
			if(conn!=null)
				try {
					conn.close();
				}catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}
}

(2)ICMD介面原始碼

package src.cn.edu.zucc.waimai.itf;

import java.util.List;

import src.cn.edu.zucc.waimai.model.BeanCMD;
import src.cn.edu.zucc.waimai.model.BeanOrder;
import src.cn.edu.zucc.waimai.model.BeanQs;
import src.cn.edu.zucc.waimai.model.BeanQsbill;
import src.cn.edu.zucc.waimai.model.BeanSj;
import src.cn.edu.zucc.waimai.model.BeanSjFL;
import src.cn.edu.zucc.waimai.model.BeanSjMJ;
import src.cn.edu.zucc.waimai.model.BeanSjYHQ;
import src.cn.edu.zucc.waimai.model.BeanSp;
import src.cn.edu.zucc.waimai.model.BeanUser;
import src.cn.edu.zucc.waimai.model.BeanUserAdd;
import src.cn.edu.zucc.waimai.util.BaseException;

public interface ICMD {
	/**
	 * 騎手接單
	 * 能修改姓名、等級
	 */
	public void QSJD(BeanQs qs,BeanOrder order) throws BaseException;
	/**
	 * 修改訂單狀態
	 * 能修改姓名、等級
	 */
	public void modifyOrder(BeanOrder order,String state) throws BaseException;
	/**
	 * 提取當前所有訂單資訊
	 * @return
	 * @throws BaseException
	 */
	public List<BeanOrder> loadAllOrder()throws BaseException;
	/**
	 * 修改騎手
	 * 能修改姓名、等級
	 */
	public void modifyQS(BeanQs qs,String name,String grade) throws BaseException;
	/**
	 * 洗掉騎手
	 * 需要騎手沒有接過單
	 */
	public void deleteQS(BeanQs qs) throws BaseException;
	/**
	 * 新增騎手
	 * 包含姓名,日期,等級
	 */
	public void regQS(String name,String grade)throws BaseException;
	/**
	 * 修改商家優惠券
	 * 能修改優惠金額、集單要求、增加天數
	 */
	public void modifyMJ(BeanSjMJ sjmj,String top,String count,String ifmj) throws BaseException;
	/**
	 * 洗掉商家優惠券
	 * 
	 */
	public void deleteMJ(BeanSjMJ sjmj) throws BaseException;
	/**
	 * 新增商家優惠券
	 * 包含優惠金額,集單要求,活動天數
	 */
	public void regMJ(BeanSj sj,String top,String count,String ifmj)throws BaseException;
	/**
	 * 修改商家優惠券
	 * 能修改優惠金額、集單要求、增加天數
	 */
	public void modifyYHQ(BeanSjYHQ sjyhq,String youhui_money,String jidan,String days) throws BaseException;
	/**
	 * 洗掉商家優惠券
	 * 
	 */
	public void deleteYHQ(BeanSjYHQ sjyhq) throws BaseException;
	/**
	 * 新增商家優惠券
	 * 包含優惠金額,集單要求,活動天數
	 */
	public void regYHQ(BeanSj sj,String youhui_money,String jidan,String days)throws BaseException;
	/**
	 * 修改商品
	 * 能修改商品名、商品價格、商品余量
	 */
	public void modifySP(BeanSp sp,String name,String price,String left) throws BaseException;
	/**
	 * 洗掉商品
	 * 
	 */
	public void deleteSP(BeanSp sp) throws BaseException;
	/**
	 * 修改商家
	 * 僅能修改分欄名
	 */
	public void modifySjFL(BeanSjFL sjfl,String name) throws BaseException;
	/**
	 * 洗掉商家分欄
	 * 需要分欄內無商品
	 */
	public void deleteSjFL(BeanSjFL sjfl) throws BaseException;
	/**
	 * 修改商家
	 * 僅能修改商家名和星級
	 */
	public void modifySj(BeanSj sj,String name,String xinji) throws BaseException;
	/**
	 * 洗掉商家
	 * 需要無分欄
	 */
	public void deleteSj(BeanSj sj) throws BaseException;
	/**
	 * 提取當前所有用戶地址資訊
	 * @return
	 * @throws BaseException
	 */
	public List<BeanUserAdd> loadAllYHadd(BeanUser user)throws BaseException;
	/**
	 * 注冊:
	 * 要求用戶名不能重復,不能為空
	 * 兩次輸入的密碼必須一致,密碼不能為空
	 * 如果注冊失敗,則拋出例外
	 * @param userid
	 * @param pwd  密碼
	 * @param pwd2 重復輸入的密碼
	 * @return
	 * @throws BaseException
	 */
	public BeanUser reg(String username,int usersex, String pwd,String pwd2,String userphonenum,
			String usere_mail,String usercity) throws BaseException;
	/**
	 * 提取當前所有用戶資訊
	 * @return
	 * @throws BaseException
	 */
	public List<BeanUser> loadAllYH()throws BaseException;
	/**
	 * 提取當前所有騎手資訊
	 * @return
	 * @throws BaseException
	 */
	public List<BeanQs> loadAllQS()throws BaseException;
	/**
	 * 提取當前所有騎手賬單資訊
	 * @return
	 * @throws BaseException
	 */
	public List<BeanQsbill> loadAllQSbill(BeanQs qs)throws BaseException;
	/**
	 * 登陸
	 * 1、如果用戶不存在或者密碼錯誤,拋出一個例外
	 * 2、如果認證成功,則回傳當前用戶資訊
	 * @param userid
	 * @param pwd
	 * @return
	 * @throws BaseException
	 */
	public BeanCMD login(String username,String pwd)throws BaseException;
	/**
	 * 提取當前所有管理員資訊
	 * @return
	 * @throws BaseException
	 */
	public List<BeanCMD> loadAll()throws BaseException;
	/**
	 * 新增
	 * 1、如果用戶不存在或者密碼錯誤,拋出一個例外
	 * 2、如果認證成功,則回傳當前用戶資訊
	 * @param userid
	 * @param pwd
	 * @return
	 * @throws BaseException
	 */
	public BeanCMD reg(String cmdusername,String cmdpwd,String username,String pwd)throws BaseException;
	/**
	 * 修改
	 * 1、如果用戶不存在或者密碼錯誤,拋出一個例外
	 * 2、如果認證成功,則回傳當前用戶資訊
	 * @param userid
	 * @param pwd
	 * @return
	 * @throws BaseException
	 */
	public BeanCMD modify(String cmdusername,String cmdpwd,String username,String pwd)throws BaseException;
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/245032.html

標籤:Java

上一篇:Java的多型機制原理

下一篇:Http協議入門、回應與請求行、HttpServletRequest物件的使用、請求引數獲取和編碼問題

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more