java.lang.OutOfMemoryError:Java堆空间

0 java jdbc

我每隔30秒调用一次mysql Prepared语句就会出现这个错误,这是被调用的代码:

public static int getUserConnectedatId(Connection conn, int i) throws SQLException {
    pstmt = conn.prepareStatement("SELECT UserId from connection where ConnectionId ='" + i + "'");
    ResultSet rs = pstmt.executeQuery();
    int id = -1;
    if (rs.next()) {
        id = rs.getInt(1);
    }
    pstmt = null;
    rs = null;
    return id;
}
Run Code Online (Sandbox Code Playgroud)

不确定问题是什么:s

dty*_*dty 7

您需要关闭您创建的所有资源 - 准备好的语句,结果集等.