0

I am working on a JAVA program which need to update database from text files. I have successfully inserted and updated data. But i am facing a problem with here, this method. Query runs without error and giving me the response. But the database table is not updating.

private void filteData() {
        System.out.println("filteData");
        Statement statementAtenLogInsert = null; 
        Statement statementqCheck = null; 
        Statement statementUpdateProLog = null; 
        Statement statementEnterError = null; 
        ResultSet rs = null;
        int rcount;

        //Update successfull attendance_test
        String attenLogInsertSuccess = "INSERT INTO attendance_log (user_id, check_in, check_out) SELECT user_id, check_in, check_out FROM process_log WHERE flag = 'S'";

        try {
            statementAtenLogInsert = connection.createStatement();
            statementAtenLogInsert.execute(attenLogInsertSuccess);
            int qSuccess = statementAtenLogInsert.executeUpdate(attenLogInsertSuccess);

            System.out.println("qSuccess " + qSuccess);

            if(qSuccess > 0){

                String deleteProcessLog = "DELETE FROM process_log WHERE flag = 'S'";
                statementAtenLogInsert.execute(deleteProcessLog);

            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

Here the attenLogInsertSuccess and deleteProcessLog queries are not working. Mean nothing happened from database table side. But qSuccess giving me a value. That means attenLogInsertSuccess is triggering. But nothing happened from mysql side.

D.Madu
  • 507
  • 2
  • 8
  • 28

1 Answers1

2

You need to close your connection in order to flush the changes to the database.

Try adding connection.close(); somewhere in your pipeline, typically you close the connection in a finally block to ensure it is always closed but it appears you have defined your connection elsewhere, presumably for re-use in the calling function.

You also need to close your statements before closing the connection. See this similar answer for the pattern.

Community
  • 1
  • 1
gwnp
  • 1,127
  • 1
  • 10
  • 35