繁体   English   中英

MYSQL插入查询未将数据更新到JAVA中的表

[英]MYSQL Insert query not updating data to the table in JAVA

我正在研究需要从文本文件更新数据库的JAVA程序。 我已成功插入和更新数据。 但是我在这里遇到这种方法的问题。 查询运行没有错误,并给了我响应。 但是数据库表未更新。

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();
        }


    }

这里的attenLogInsertSuccessdeleteProcessLog查询不起作用。 意味着从数据库表侧什么也没发生。 但是qSuccess给了我一个价值。 这意味着attenLogInsertSuccess正在触发。 但是从mysql方面没有任何反应。

您需要关闭连接才能将更改刷新到数据库。

尝试添加connection.close(); 通常,您可以在管道中的某个位置关闭finally块中的连接,以确保始终关闭该连接,但是您似乎已在其他位置定义了连接,可能是在调用函数中重用了。

在关闭连接之前,您还需要关闭语句。 有关模式,请参见类似的答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM