0

i get this error when calling a mysql Prepared Statement every 30 seconds this is the code which is been called:

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

not sure what the problem is :s

1
  • check your memory. linux command: free Commented Jun 10, 2010 at 8:43

3 Answers 3

7

You need to close all the resources you create - prepared statement, resultset, etc.

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

1 Comment

ahh of course! when you look at something for so long you dont see the obvious! :p
1

Why not make the query parameterized and simply change the connection ID? That's how prepared statements were intended to be used. That way you only compile the statement once, and re-use the compiled query plan (or whatever your DB compiles your query into).

Comments

-2

Because you are running out of memory as your ResultSet is occupyng more memory compared to default memory.

Solution: At the time of starting the application use this argument java or javaw -Xms 25M -Xmx 1024M

1 Comment

This is completely ridiculous advice. How do you know the process isn't already started with -Xmx2g? How do you know that -Xms25m is not going to cause the process to thrash when it starts? How do you know -Xmx1024m is going to be enough to solve the problem?

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.