有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Hibernate读取和更新大型数据

我需要从表中读取大数据并更新它

什么是最好的解决方案

我正在使用流,但它有问题

Caused by: java.sql.SQLException: Streaming result set com.mysql.cj.protocol.a.result.ResultsetRowsStreaming@3ea407e4 is still active.

在给定连接上打开并使用任何流结果集时,不得发出任何语句。在尝试更多查询之前,请确保已对任何活动流结果集调用了.close()。 我的代码如下:

Stream<UserNotificationDTO> dtoStream = userNotificationRepo.fetchAllUnreadByUserId(userId);
        dtoStream.forEach(userNotifyDTO -> {
            userNotifyDTO.setOpened(true);
            userNotificationRepo.save(userNotifyDTO);
        });

共 (2) 个答案

  1. # 1 楼答案

    这是一个mysql限制。在遍历结果时不能发出其他查询:

    When using large result sets with MySQL there are a number of documented limitations... The net effect of these limitations is that you will have to read all of the rows of a result set (or close the connection) before you can issue any other queries on the connection, or an exception will be thrown

    资料来源:http://openjpa.apache.org/builds/2.4.2/apache-openjpa/docs/dbsupport_mysql.html

  2. # 2 楼答案

    它可以是以下两种情况之一:

    1. 您没有关闭流或结果集
    2. com版本有问题。mysql。希杰。jdbc。您使用的驱动程序