PrivateQueryRunnerqr = newQueryRunner (JdbcUtil. getDataSource ());

Source: Internet
Author: User
Packagecom. itheima. tfy. dao. impl; importjava. util. list; importorg. apache. commons. dbutils. queryRunner; importorg. apache. commons. dbutils. handlers. beanHandler; importor 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) valu Es (?,?,?,?,?,?) "; Object [] params = {orders. getId (), orders. getOrdersNum (), orders. getNum (), orders. getTotalPrice (), orders. isState (), user. getId ()}; qr. update (SQL, params);} catch (Exception e) {BookStoreLogger. error ("failed to add order"); throw new DaoException (e) ;}} public List FindAllOrders (Orders orders) {try {String SQL = "select * from orders"; return qr. query (SQL, new BeanListHandler (Orders. class);} catch (Exception e) {BookStoreLogger. error ("failed to query all Orders"); throw new DaoException (e) ;}} public Orders findMyOrders (User user User) {try {String SQL = "select * from orders where user_id =? "; Return qr. query (SQL, new BeanHandler (Orders. class), user. getId ();} catch (Exception e) {BookStoreLogger. error ("failed to query my order"); throw new DaoException (e) ;}} public List FindOrdersByUserId (String userId) {try {String SQL = "select * from orders where user_id =? "; Return qr. query (SQL, new BeanListHandler (Orders. class), userId);} catch (Exception e) {BookStoreLogger. error ("failed to query my order"); throw new DaoException (e);} public List FindOrdersByState (boolean state) {try {String SQL = "select * from orders where state =? "; Return qr. query (SQL, new BeanListHandler (Orders. class), state);} catch (Exception e) {BookStoreLogger. error ("failed to query order based on delivery status"); 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) {www.2cto.com BookStoreLogger. error ("An error occurred while updating the database orders table based on the shipping status !!! "); Throw new DaoException (e );}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.