Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package konditer_reorganized_database.dao; import java.sql.Types; import java.util.ArrayList; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; import javax.activation.DataSource; import static konditer_reorganized_database.Main.cakeDao; import static konditer_reorganized_database.Main.ordereDao; import konditer_reorganized_database.bean.Ordere; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; /** * * @author */ @Repository public class OrdereDao implements OrdereDaoInterface { private DataSource dataSource = null; private JdbcTemplate jdbcTemplate = null; public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } @Autowired public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } @Override public void addOrdere(int orderId, int customerId, int orderStatusId, int deliveryId, Date orderDateIncome, Date orderDateEnd, double orderCakePrice, double orderDeliveryPrice, String orderInsidesId, String orderInfo) { String SQL_QUERY = "INSERT INTO orders ( ORDER_ID, " + "CUSTOMER_ID, " + "ORDER_STATUS_ID, " + "DELIVERY_ID, " + "ORDER_DATE_INCOME, " + "ORDER_DATE_END, " + "ORDER_CAKE_PRICE, " + "ORDER_DELIVERY_PRICE, " + "ORDER_INSIDES_ID, " + "ORDER_INFO ) " + "VALUES (?,?,?,?,?,?,?,?,?,?)"; int rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { orderId, customerId, orderStatusId, deliveryId, orderDateIncome, orderDateEnd, orderCakePrice, orderDeliveryPrice, orderInsidesId, orderInfo }, new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.DOUBLE, Types.DOUBLE, Types.VARCHAR, Types.VARCHAR }); Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, " : {0} .", rowCount); System.out.println(ordereDao.getOrdere(orderId).toString()); } @Override public Ordere getOrdere(int orderId) { String SQL_QUERY = "SELECT ORDER_ID, " + "CUSTOMER_ID, " + "ORDER_STATUS_ID, " + "DELIVERY_ID, " + "ORDER_DATE_INCOME, " + "ORDER_DATE_END, " + "ORDER_CAKE_PRICE, " + "ORDER_DELIVERY_PRICE, " + "ORDER_INSIDES_ID, " + "ORDER_INFO, TIMESTAMP " + "FROM orders " + "WHERE ORDER_ID = ?"; Ordere order = (Ordere) jdbcTemplate.queryForObject(SQL_QUERY, new Object[] { orderId }, new BeanPropertyRowMapper(Ordere.class)); return order; } @Override public ArrayList<Ordere> getAllOrders() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public ArrayList<Ordere> getAllOrders(String searchValue) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public ArrayList<Ordere> getAllOrdersByCustomerId(int customerId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public ArrayList<Ordere> getAllOrdersByOrderStatusId(int orderStatusId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public ArrayList<Ordere> searchAllOrders(String sqlQuery) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public int updateOrdere(int orderId, int newCustomerId, int newDeliveryId, int newOrderStatusId, Date newOrderDateIncome, Date newOrderDateEnd, double orderCakePrice, double newOrderDeliveryPrice, String orderInsidesId, String newOrderInfo) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public int deleteOrdere(int orderId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }