I'm using UCanAccess to connect my JavaFX app with the database on the shared drive. The first time I open the app and run some query the initial connection to the database takes around 25 seconds.
I put some timestamps and found that the root cause is the below method, specifically the first try catch block takes 25 seconds to execute. After that, every other time I call this method everything runs within a split of second. Any suggestions on how could this be resolved?
public void openDB(){
// Load MS access driver class
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("There was an error while connecting to the database");
e.printStackTrace();
}
String databasePath ="jdbc:ucanaccess:////server\\MyDB.accdb";
try {
this.connection = DriverManager.getConnection(databasePath, "", "");
this.connection.setAutoCommit(false);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
this.statement = connection.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}