Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.15 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package be.hogent.iii.cmodels.bo;
  6.  
  7. import be.hogent.iii.cmodels.excepties.JDBCExceptie;
  8. import be.hogent.iii.cmodels.interfaces.IDataStorage;
  9. import be.hogent.iii.cmodels.interfaces.IOrder;
  10. import be.hogent.iii.cmodels.interfaces.ICustomer;
  11. import be.hogent.iii.cmodels.interfaces.IProduct;
  12. import java.sql.Connection;
  13. import java.sql.DriverManager;
  14. import java.util.List;
  15. import java.util.ResourceBundle;
  16.  
  17. /**
  18.  *
  19.  * @author kvdw
  20.  */
  21. public class JDBCDataStorage implements IDataStorage {
  22.  
  23.     private String userName = "";
  24.     private String password = "";
  25.     private String url = "";
  26.     private ResourceBundle bp ;
  27.  
  28.     public JDBCDataStorage() throws ClassNotFoundException {
  29.  
  30.         bp = ResourceBundle.getBundle("db");
  31.        
  32.         userName = bp.getString("USERNAME") ;
  33.         password = bp.getString("PASSWORD") ;
  34.         url = bp.getString("CONNSTRING") ;
  35.  
  36.         String driverclassname = bp.getString("DRIVER") ;
  37.  
  38.         try{
  39.             Class.forName ( driverclassname );
  40.         }catch( Exception e ){
  41.             System.out.println ("Database connection failed");
  42.         }
  43.     }
  44.  
  45.     private void closeConnection( Connection conn ){
  46.         try
  47.         {
  48.             conn.close ();
  49.             //System.out.println ("Database connection terminated");
  50.         }
  51.         catch (Exception e) { /* ignore close errors */ }
  52.     }
  53.  
  54.     private Connection getConnection(){
  55.         try{
  56.             return DriverManager.getConnection (url, userName, password);
  57.         }catch( Exception e ){
  58.             System.out.println ("Database connection failed");
  59.             return null ;
  60.         }
  61.     }
  62.    
  63.     public List<IProduct> getProducts() throws JDBCExceptie {
  64.         List<IProduct> products = null;
  65.  
  66.         Connection conn = getConnection();
  67.            
  68.         closeConnection( conn );
  69.  
  70.         return products;
  71.     }
  72.  
  73.    
  74.     public List<ICustomer> getCustomers() throws JDBCExceptie {
  75.         List<ICustomer> customers = null;
  76.  
  77.         Connection conn = getConnection();
  78.  
  79.         closeConnection( conn );
  80.  
  81.         return customers;
  82.     }
  83.    
  84.     //Lijst van bestellingen zonder details
  85.     public List<IOrder> getOrders() throws JDBCExceptie {
  86.         List<IOrder> orders = null;
  87.  
  88.         Connection conn = getConnection();
  89.  
  90.         closeConnection( conn );
  91.  
  92.         return orders;
  93.     }
  94.    
  95.    
  96.     //Lijst van bestellingen van een gegeven klant (zonder details)
  97.     public List<IOrder> getOrders(int customerNumber) throws JDBCExceptie {
  98.         List<IOrder> orders = null;
  99.  
  100.         Connection conn = getConnection();
  101.  
  102.         closeConnection( conn );
  103.  
  104.         return orders;
  105.     }
  106.    
  107.        
  108.     public boolean addProduct(IProduct product) throws JDBCExceptie {
  109.         boolean resultaat = false;
  110.  
  111.         Connection conn = getConnection();
  112.  
  113.         closeConnection( conn );
  114.  
  115.         return resultaat;
  116.     }
  117.    
  118.    
  119.     public boolean addOrder(IOrder order) throws JDBCExceptie {
  120.         boolean resultaat = false;
  121.  
  122.         Connection conn = getConnection();
  123.  
  124.         closeConnection( conn );
  125.  
  126.         return resultaat;
  127.  
  128.     }
  129.    
  130.    
  131.     public boolean addCustomer(ICustomer customer) throws JDBCExceptie {
  132.         boolean resultaat = false;
  133.  
  134.         Connection conn = getConnection();
  135.  
  136.         closeConnection( conn );
  137.  
  138.         return resultaat;
  139.     }
  140.    
  141.    
  142.     public boolean modifyCustomer(ICustomer customer) throws JDBCExceptie {
  143.         boolean resultaat = false;
  144.  
  145.         Connection conn = getConnection();
  146.  
  147.         closeConnection( conn );
  148.  
  149.         return resultaat;
  150.     }
  151.    
  152.    
  153.     public boolean deleteCustomer(int customerNumber) throws JDBCExceptie {
  154.         boolean resultaat = false;
  155.  
  156.         Connection conn = getConnection();
  157.  
  158.         closeConnection( conn );
  159.  
  160.         return resultaat;
  161.     }
  162.    
  163.    
  164.     public double getTotal(int customerNumber) throws JDBCExceptie {
  165.         double resultaat = 0;
  166.  
  167.         Connection conn = getConnection();
  168.  
  169.         closeConnection( conn );
  170.  
  171.         return resultaat;
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement