Hi all,

I am getting into an OutOfMemory error in my case. Which is similar to the
case below. After examining the heap dump, I could find the
PreparedStatement is hold too many internal objects and might lead to the
MemoryLeak.
I am not for sure whether it is caused by my closing the statement after the
long loop, thus causing the client side of derby cashing too many things.
Will that be the problem? Thanks.

                connection.setAutoCommit(false);
                connection.setReadOnly(false);
                connection

.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);

                PreparedStatement selectProfile = connection
                        .prepareStatement(
                                "SELECT business_unit, country, bu_alias "
                                        + "FROM person WHERE email = ? "
                                        + "FOR UPDATE",
                                ResultSet.TYPE_FORWARD_ONLY,
                                ResultSet.CONCUR_UPDATABLE);
                PreparedStatement insertProfile = connection
                        .prepareStatement("INSERT INTO person(email,
business_unit, country, bu_alias) "
                                + "VALUES (?, ?, ?, ?)");

                for (int i = 0; i < aQuiteBigNumber; ++i) {
                    // omitted some code here
                    ResultSet selectProfileSet =
selectProfile.executeQuery();

                    if (selectProfileSet.next()) {
                        System.out.println("Update profile: " + email);
                        selectProfileSet.updateString(1, bu);
                        selectProfileSet.updateString(2, country);
                        selectProfileSet.updateString(3, bu_alias);
                        selectProfileSet.updateRow();
                        selectProfileSet.close();
                    }
                    else {
                        selectProfileSet.close();

                        System.out.println("Insert profile: " + email);
                        insertProfile.setString(1, email);
                        insertProfile.setString(2, bu);
                        insertProfile.setString(3, country);
                        insertProfile.setString(4, bu_alias);

                        insertProfile.executeUpdate();
                    }
                }

                selectProfile.close();
                insertProfile.close();
                connection.commit();

Reply via email to