0

I have a huge MS Access database file (aprrox. 1gb) and about 5 different GUI (FXML). Each fxml contains data from different tables. I am using ucanaccess to connect with database. Now I am having problem in connecting with database. I never get connection. It works fine with smaller database file. I am using service and task for background thread. Could someone tell me what can be the best approach to overcome this problem.

private Service backgroundService;
private Connection ucaConn;

@FXML private void handleButtonAction(ActionEvent event) {

            backgroundService = new Service() {

                @Override
                protected Task createTask() {


                    return new Task() {

                        @Override
                        protected Object call() throws Exception {

                            try {

                                ucaConn = getUcanaccessConnection(DataCarrier.getInstance().getDatabaseLocation());
                            } catch (SQLException | IOException ex) {
                                Logger.getLogger(HomeController.class.getName()).log(Level.SEVERE, null, ex);
                            }

                            return null;
                        }
                    };
                }
            };
            backgroundService.setOnSucceeded(new EventHandler<WorkerStateEvent>() {

                @Override
                public void handle(WorkerStateEvent event) {

                    System.out.println("Done");
                    errorMessage.textProperty().unbind();
                    String timeStamp = new SimpleDateFormat("mm:ss").format(Calendar.getInstance().getTime());
                    System.out.println("End time: " + timeStamp);
                }

            });

            errorMessage.textProperty().bind(backgroundService.messageProperty());
            backgroundService.restart();
        }
    }
}

private static Connection getUcanaccessConnection(String pathNewDB) throws SQLException,
        IOException {
    String url = UcanaccessDriver.URL_PREFIX + pathNewDB + ";newDatabaseVersion=V2003";

    return DriverManager.getConnection(url, "sa", "");
}
PDM
  • 31
  • 1
  • 5
  • You may have the need to use the keepMirror parameter, but firstly, do you have five different potential processes accessing to the same db, right? – jamadei Jul 16 '15 at 07:03
  • Yes, I need to process different tables' data wit same db. – PDM Jul 16 '15 at 07:07
  • So, using 5 filter databases, each one linking just the tables of the main database that a specific gui elaborates, must be a first step. – jamadei Jul 16 '15 at 07:10
  • Thanks for answer. But the problem I am having now is on getting connection to database. Let me try that keepMirror parameter. Do you have any experience how long it might take to create a connection to MS Access db of 1gb? – PDM Jul 16 '15 at 07:14
  • Please, it's a memory issue, that must be partially solved using 5 different proxy databases, so firstly follow this suggestion. The time depend on the databases content. Are there many db indexes?Are there many BLOB/OLEs? – jamadei Jul 16 '15 at 07:30
  • There are OLES but empty. I deleted some tables and Compact database. Sized reduced to 100mb and it took around 10minutes. I haven't yet done any query, it is only for connection now. – PDM Jul 16 '15 at 07:36
  • Okey, ensure to have the 2.0.9.5 and try the Lobscale=1 connection parameter. In the way I'm suggesting, each gui will use just the memory it needs. – jamadei Jul 16 '15 at 07:40
  • Thanks for your answer. I will follow your suggestions. I will come back to you, if I get problem. – PDM Jul 16 '15 at 07:43
  • @jamadai, isn't it possible to use same db connection to multiple controllers. I would like to query data in different controller using already established connection. – PDM Jul 16 '15 at 10:33
  • I don't understand your need, but you may consider that all connection established after the very first one (in the current jvm life) will be istantaneous. – jamadei Jul 16 '15 at 11:19
  • Ok lets say I have controllerA, controllerB and controllerC. Each controller has some actions and each action needs to query different data from tables according to input values. Since the database file is so big, it will take time for each query because I need to create connection for each action (query). Isn't there any way to use one connection for all the possible queries to happen in runtime? – PDM Jul 16 '15 at 11:23
  • You don't optimize anything by sharing the connection, as after the very first connection to a given database, the next connections to that datatabase will take 1-2 milliseconds. You may incur in a deadlock instead, if multiple thread are concurrently accessing to the same connection. – jamadei Jul 17 '15 at 21:38

0 Answers0