首先,有一个模糊查询订单信息的存储过程:
#通过模糊查找订单信息
drop procedure if exists findOrder;
delimiter ;;
create procedure findOrder(IN _orderid varchar(10), IN _cid varchar(10), IN _dessertnum varchar(20),
IN _count varchar(10), IN _bills varchar(10), IN _createtime varchar(20), IN _destination varchar(50),
IN _paymethod varchar(20), IN _deletestate varchar(10))
begin
set _orderid = concat('%', _orderid , '%');
set _cid = concat('%', _cid , '%');
set _dessertnum = concat('%', _dessertnum , '%');
set _count = concat('%', _count , '%');
set _bills = concat('%', _bills , '%');
set _createtime = concat('%', _createtime , '%');
set _destination = concat('%', _destination , '%');
set _paymethod = concat('%', _paymethod , '%');
set _deletestate = concat('%', _deletestate , '%');
select * from order_form where delete_state=1 and (order_id like _orderid or c_id like _cid or dessert_num like _dessertnum
or count like _count or bills like _bills or create_time like _createtime or destination like _destination
or pay_method like _paymethod or delete_state like _deletestate);
end;;
delimiter ;
然后再业务逻辑类中调用该存储过程:
conn= tastetime_utils.getConnection();
CallableStatementcs=conn.prepareCall("{callfindOrder(?,?,?,?,?,?,?,?,?)}");
cs.setString(1, aa);
cs.setString(2, aa);
cs.setString(3, aa);
cs.setString(4, aa);
cs.setString(5, aa);
cs.setString(6, aa);
cs.setString(7, aa);
cs.setString(8, aa);
cs.setString(9, aa);
rs=cs.executeQuery();
此处的CallableStatement 类似于 StatStatement