private QueryRunner qr=new QueryRunner(JdbcUtil.getDataSource());
来源:互联网 发布:seo站内优化工资 编辑:程序博客网 时间:2024/05/17 00:09
package com.itheima.tfy.dao.impl;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import com.itheima.tfy.domain.Orders;
import com.itheima.tfy.domain.User;
import com.itheima.tfy.exception.DaoException;
import com.itheima.tfy.util.BookStoreLogger;
import com.itheima.tfy.util.JdbcUtil;
public class OrdersDaoImpl {
private QueryRunner qr=new QueryRunner(JdbcUtil.getDataSource());
public void addOrders(Orders orders,User user){
try{
String sql="insert into orders (id,ordernum,num,totalprice,state,user_id) values(?,?,?,?,?,?)";
Object[]params={orders.getId(),orders.getOrdersNum(),orders.getNum(),orders.getTotalPrice(),orders.isState(),user.getId()};
qr.update(sql, params);
}catch(Exception e){
BookStoreLogger.error("添加订单失败");
throw new DaoException(e);
}
}
public List<Orders> findAllOrders(Orders orders){
try{
String sql="select * from orders ";
return qr.query(sql, new BeanListHandler<Orders>(Orders.class));
}catch(Exception e){
BookStoreLogger.error("查询所有订单失败");
throw new DaoException(e);
}
}
public Orders findMyOrders(User user){
try{
String sql="select * from orders where user_id=?";
return qr.query(sql, new BeanHandler<Orders>(Orders.class),user.getId());
}catch(Exception e){
BookStoreLogger.error("查询我的订单失败");
throw new DaoException(e);
}
}
public List<Orders> findOrdersByUserId(String userId) {
try{
String sql="select * from orders where user_id=?";
return qr.query(sql, new BeanListHandler<Orders>(Orders.class),userId);
}catch(Exception e){
BookStoreLogger.error("查询我的订单失败");
throw new DaoException(e);
}
}
public List<Orders> findOrdersByState(boolean state) {
try{
String sql="select * from orders where state=?";
return qr.query(sql, new BeanListHandler<Orders>(Orders.class),state);
}catch(Exception e){
BookStoreLogger.error("根据发货状态查询订单失败");
throw new DaoException(e);
}
}
public void updateOdersBySate(boolean state,String ordersId) {
try{
String sql="update orders set state=? where id=?";
Object[]params={state,ordersId};
qr.update(sql, params);
}catch(Exception e)
{
BookStoreLogger.error("根据发货状态更新数据库 orders表失败!!!");
throw new DaoException(e);
}
}
}
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import com.itheima.tfy.domain.Orders;
import com.itheima.tfy.domain.User;
import com.itheima.tfy.exception.DaoException;
import com.itheima.tfy.util.BookStoreLogger;
import com.itheima.tfy.util.JdbcUtil;
public class OrdersDaoImpl {
private QueryRunner qr=new QueryRunner(JdbcUtil.getDataSource());
public void addOrders(Orders orders,User user){
try{
String sql="insert into orders (id,ordernum,num,totalprice,state,user_id) values(?,?,?,?,?,?)";
Object[]params={orders.getId(),orders.getOrdersNum(),orders.getNum(),orders.getTotalPrice(),orders.isState(),user.getId()};
qr.update(sql, params);
}catch(Exception e){
BookStoreLogger.error("添加订单失败");
throw new DaoException(e);
}
}
public List<Orders> findAllOrders(Orders orders){
try{
String sql="select * from orders ";
return qr.query(sql, new BeanListHandler<Orders>(Orders.class));
}catch(Exception e){
BookStoreLogger.error("查询所有订单失败");
throw new DaoException(e);
}
}
public Orders findMyOrders(User user){
try{
String sql="select * from orders where user_id=?";
return qr.query(sql, new BeanHandler<Orders>(Orders.class),user.getId());
}catch(Exception e){
BookStoreLogger.error("查询我的订单失败");
throw new DaoException(e);
}
}
public List<Orders> findOrdersByUserId(String userId) {
try{
String sql="select * from orders where user_id=?";
return qr.query(sql, new BeanListHandler<Orders>(Orders.class),userId);
}catch(Exception e){
BookStoreLogger.error("查询我的订单失败");
throw new DaoException(e);
}
}
public List<Orders> findOrdersByState(boolean state) {
try{
String sql="select * from orders where state=?";
return qr.query(sql, new BeanListHandler<Orders>(Orders.class),state);
}catch(Exception e){
BookStoreLogger.error("根据发货状态查询订单失败");
throw new DaoException(e);
}
}
public void updateOdersBySate(boolean state,String ordersId) {
try{
String sql="update orders set state=? where id=?";
Object[]params={state,ordersId};
qr.update(sql, params);
}catch(Exception e)
{
BookStoreLogger.error("根据发货状态更新数据库 orders表失败!!!");
throw new DaoException(e);
}
}
}
- private QueryRunner qr=new QueryRunner(JdbcUtil.getDataSource());
- private QueryRunner qr=new QueryRunner(JdbcUtil.getDataSource());
- private QueryRunner qr= new QueryRunner(DbcpUtil.getDataSource());
- private QueryRunner qr=new QueryRunner();
- private QueryRunner qr=new QueryRunner();
- QueryRunner
- QueryRunner
- QueryRunner
- queryRUNNER
- queryrunner用法
- QueryRunner类
- QueryRunner使用
- QueryRunner使用
- QueryRunner-2
- QueryRunner的使用
- QueryRunner的使用
- QueryRunner的使用
- QueryRunner的使用
- SQL Server 索引(index)
- PHP魔术方法
- Core Java (七) Java中的static修饰符
- 史上最强IDE集成开发环境——Code::Blocks安装过程(吐血推荐)
- sql delete 语句 删除键
- private QueryRunner qr=new QueryRunner(JdbcUtil.getDataSource());
- Fedora 17 无法播放mp3 rmvb
- javaWeb_13-Http响应和响应状态行详解
- Eclipse快捷键-----原来Eclipse完全不许用鼠标的,不用羡慕VI了
- 多继承引发的诡异bug (cocos2d-x CCObject)
- pywinauto登陆QQ
- Jsoup 乱码问题解决
- JSP中使用CKEditor3.6入门教程
- Visual Studio 2012 - Visual C++ CMFCToolBar Class