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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

this can be a comment @gwnp, you can at least show how to close the connection :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.