Exception Closing a PreparedStatement
Posted by: Brian Lipa
Date: February 01, 2005 12:44PM

Hi all. I am using MySQL within the JBoss application server. I have not recompiled or even editted the code for a couple of days and all of a sudden this morning I am getting the following exception when I query for result sets around 5000 rows. Here is the code for my queries, the exception is occurring at the first pstmt.close() call.

Does anyone have an opinion or idea of why this might be happening? I am using MySQL 4.0.21 as my database and would like to avoid an upgrade to 4.1 at this time.

Thank you in advance.
Brian


CODE:

java.sql.PreparedStatement pstmt = null;
ResultSet rs = null;
LinkedList list = new LinkedList();

sql = sql + " ID<" + (lastID) + " ORDER BY ID DESC LIMIT " +
resultSize;

int rSize=0;

pstmt = conn.prepareStatement(sql,
PreparedStatement.RETURN_GENERATED_KEYS);
pstmt.setMaxRows(resultSize);
rs = pstmt.executeQuery();

// Get all of the objects
while (rs.next())
{
rSize++;
}
if (rs.last())
lastID = rs.getInt(2);

// if this is true, then this means that there are no more info objects
// and we should remove the query
if (rSize < resultSize)
{
terminateQuery(queryID);
return list;
}

try
{
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
e.printStackTrace();
}

// update the query table with the query id...
pstmt = conn.prepareStatement("UPDATE QUERY.QUERY SET LAST_ROW=" +
lastID + " WHERE QUERYID='" + queryID + "'");
pstmt.executeUpdate();

// gc
pstmt.close();
rs = null;
pstmt = null;

EXCEPTION:

13:28:22,229 INFO [STDOUT] java.sql.SQLException:
Error during query: Unexpected Exception: java.lang.NegativeArraySizeException message given: null

Nested Stack Trace:


** BEGIN NESTED EXCEPTION **

java.lang.NegativeArraySizeException

STACKTRACE:

java.lang.NegativeArraySizeException
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:280)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1325)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1224)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2248)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2208)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2189)
at com.mysql.jdbc.Connection.unsetMaxRows(Connection.java:2325)
at com.mysql.jdbc.Statement.close(Statement.java:809)
at com.mysql.jdbc.PreparedStatement.close(PreparedStatement.java:1281)
at org.jboss.resource.adapter.jdbc.WrappedStatement.internalClose(WrappedStatement.java:782)
at org.jboss.resource.adapter.jdbc.WrappedStatement.close(WrappedStatement.java:52)

Options: ReplyQuote


Subject
Written By
Posted
Exception Closing a PreparedStatement
February 01, 2005 12:44PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.