Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package be.hogent.iii.cmodels.bo;
- import be.hogent.iii.cmodels.excepties.JDBCExceptie;
- import be.hogent.iii.cmodels.interfaces.IDataStorage;
- import be.hogent.iii.cmodels.interfaces.IOrder;
- import be.hogent.iii.cmodels.interfaces.ICustomer;
- import be.hogent.iii.cmodels.interfaces.IProduct;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.util.List;
- import java.util.ResourceBundle;
- /**
- *
- * @author kvdw
- */
- public class JDBCDataStorage implements IDataStorage {
- private String userName = "";
- private String password = "";
- private String url = "";
- private ResourceBundle bp ;
- public JDBCDataStorage() throws ClassNotFoundException {
- bp = ResourceBundle.getBundle("db");
- userName = bp.getString("USERNAME") ;
- password = bp.getString("PASSWORD") ;
- url = bp.getString("CONNSTRING") ;
- String driverclassname = bp.getString("DRIVER") ;
- try{
- Class.forName ( driverclassname );
- }catch( Exception e ){
- System.out.println ("Database connection failed");
- }
- }
- private void closeConnection( Connection conn ){
- try
- {
- conn.close ();
- //System.out.println ("Database connection terminated");
- }
- catch (Exception e) { /* ignore close errors */ }
- }
- private Connection getConnection(){
- try{
- return DriverManager.getConnection (url, userName, password);
- }catch( Exception e ){
- System.out.println ("Database connection failed");
- return null ;
- }
- }
- public List<IProduct> getProducts() throws JDBCExceptie {
- List<IProduct> products = null;
- Connection conn = getConnection();
- closeConnection( conn );
- return products;
- }
- public List<ICustomer> getCustomers() throws JDBCExceptie {
- List<ICustomer> customers = null;
- Connection conn = getConnection();
- closeConnection( conn );
- return customers;
- }
- //Lijst van bestellingen zonder details
- public List<IOrder> getOrders() throws JDBCExceptie {
- List<IOrder> orders = null;
- Connection conn = getConnection();
- closeConnection( conn );
- return orders;
- }
- //Lijst van bestellingen van een gegeven klant (zonder details)
- public List<IOrder> getOrders(int customerNumber) throws JDBCExceptie {
- List<IOrder> orders = null;
- Connection conn = getConnection();
- closeConnection( conn );
- return orders;
- }
- public boolean addProduct(IProduct product) throws JDBCExceptie {
- boolean resultaat = false;
- Connection conn = getConnection();
- closeConnection( conn );
- return resultaat;
- }
- public boolean addOrder(IOrder order) throws JDBCExceptie {
- boolean resultaat = false;
- Connection conn = getConnection();
- closeConnection( conn );
- return resultaat;
- }
- public boolean addCustomer(ICustomer customer) throws JDBCExceptie {
- boolean resultaat = false;
- Connection conn = getConnection();
- closeConnection( conn );
- return resultaat;
- }
- public boolean modifyCustomer(ICustomer customer) throws JDBCExceptie {
- boolean resultaat = false;
- Connection conn = getConnection();
- closeConnection( conn );
- return resultaat;
- }
- public boolean deleteCustomer(int customerNumber) throws JDBCExceptie {
- boolean resultaat = false;
- Connection conn = getConnection();
- closeConnection( conn );
- return resultaat;
- }
- public double getTotal(int customerNumber) throws JDBCExceptie {
- double resultaat = 0;
- Connection conn = getConnection();
- closeConnection( conn );
- return resultaat;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement