DB.java :  » REST » ordersys01 » models » Java Open Source

Java Open Source » REST » ordersys01 
ordersys01 » models » DB.java

package models;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DB {
    private Connection con;
    private String errorMessage="";
    private static String settingFileName="settings.txt";
    private static String FXPadModelFileName="FXPadFiles.txt";
    private static String orderModelFileName="OrderModelDB.txt";

    public String getErrorMessage() {
        return errorMessage;
    }

    public Connection getCon() {
        return con;
    }
    
    public DB(){
        stablishConection();
    }

    public static String getSettingFileName(){
        return settingFileName;
    }

    public static String getFXPadModelFileName() {
        return FXPadModelFileName;
    }

    public static String getOrderModelFileName() {
        return orderModelFileName;
    }

    public static void setOrderModelFileName(String orderModelFileName) {
        DB.orderModelFileName = orderModelFileName;
    }

    private void stablishConection(){
        String data="jdbc:odbc:ordersys1";
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con=DriverManager.getConnection(data);
        }
        catch(SQLException s){
            errorMessage=s.getMessage();
            System.out.println("Error in sql exception:"+s.getMessage());
        }
         catch(Exception e){
             errorMessage=e.getMessage();
            System.out.println("Error:"+e.getMessage()+" "+e.getLocalizedMessage());
        }
    }
    public void closeConnection(){
        try{
            con.close();
        }
        catch(SQLException s){
            System.out.println("Error in DB.closeConnection:"+s.getLocalizedMessage());
        }
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.