Skip to content Skip to sidebar Skip to footer

Desktop Application And Db Connection

Lets say I have desktop application with simple login - here, in this part i have to create Connection, prepared statement which compares username and password. I use cardlayout- a

Solution 1:

You can write a properties file specific to your application and write a class to load it.

MyDatabaseProperties.properties

database.jdbc.url = jdbc:mysql://localhost:3306/database
database.jdbc.driver = "com.mysql.jdbc.Driver"database.jdbc.username = "USERNAME"database.jdbc.password = "PASSWORD"

Properties.java:

publicclassProperties {
    privatestaticfinalStringPROPERTIES_FILE="MyDatabaseProperties.properties";
    privatestaticfinalPropertiesPROPERTIES=newProperties();

    static {
        try {
            PROPERTIES.load(newFileInputStream("MyDatabaseProperties.properties"));
        } catch (IOException e) {
            // THROW YOUR EXCEPTION HERE.
        }
    }
}

You will find an excellent material on this subject here.

Solution 2:

You can create a DAO (Data Access Object) to access the table Employee, named DAOEmployee for instance (note that this class will contain methods such as addEmployee, removeEmployee, getEmployees). Then, you can have a class (DataBaseConfiguration), responsible of returning the connection to the database (using a static method, for instance).

Post a Comment for "Desktop Application And Db Connection"