Urgent - Problem with ResultSet's next function

OS - Sun Solaris 10

Java - J2SE 1.4.2

Database - Oracle 10g R2

Scenario: Java program accesses Oracle database over network.

-

I have written a multithreaded TCP server that acts as a middleware to serve other servers' database requests.

Initially it is tested OK if the return data is a lot. But lately I tested with little return data, here comes my headache. The SQLException's function printStackTrace printed errors as follows:-

java.sql.SQLException: Closed Statement: next

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)

at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1130)

at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:224)

at oracle.jdbc.driver.ScrollableResultSet.cacheRowAt(ScrollableResultSet.java:2086)

at oracle.jdbc.driver.ScrollableResultSet.isValidRow(ScrollableResultSet.java:2060)

at oracle.jdbc.driver.ScrollableResultSet.isEmptyResultSet(ScrollableResultSet.java:2027)

at oracle.jdbc.driver.ScrollableResultSet.next(ScrollableResultSet.java:333)

at oracle.jdbc.driver.SensitiveScrollableResultSet.next(SensitiveScrollableResultSet.java:80)

at oracle.jdbc.driver.UpdatableResultSet.next(UpdatableResultSet.java:251)

at jTCPClient.processInputData(jTCPClient.java:702)

at jTCPClient.run(jTCPClient.java:1198)

My code implementation is as follows:-

...

try

{

Statement sqlSelect = m_dbCon.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

ResultSet rsCLIP = sqlSelect.executeQuery(strSQL);

while (rsCLIP.next())// <-- ERROR

{

if (rsCLIP.getString(1) ==null)

continue;

sbrTemp.append(rsCLIP.getString(1)).append("|");

}

sqlSelect.close();

}

catch (SQLException exSQL)

{

exSQL.printStackTrace();

}

...

For further information, the codes are implemeted within thread class like follows:-

class jTCPClientextends Thread

{

...

}

Does any expert here has any idea about this error? Please show me the light. This error has dragged me for few sleepless nights. Thanks in advance. Hope can hear from you soon. (Pray hard...)

[2892 byte] By [cytaya] at [2007-10-2 17:37:28]
# 1

You're sharing the connection between multiple threads, aren't you? Another thread of execution has closed your connection, resulting in the closure of open result sets including this one.

Don't share the connection.

> For further information, the codes are implemeted

> within thread class like follows:-

>

> class jTCPClient extends Thread ...

You should implement Runnable, not extend Thread. It's not the cause of your problem, but don't do it again.

Finally, this is not Urgent for anyone but you. The most you'll achieve by putting that in the subject line is irritating the very people you're seeking help from.

dcmintera at 2007-7-13 18:54:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Dear dcminter,

Thanks for the prompt reply. I really appreciate that and sorry for the word URGENT that is sensitive to you. I put the word in the subject line is because I have no choice but to attract good people like you's attentions on this issue.

For your information, the database connection is not created and shared among the threads. It is created within each thread when the thread starts.

By the way, sorry to tell you that I'm quite new to Java. What's so special about Runnable than extending Thread?

Thanks again. :-)

cytaya at 2007-7-13 18:54:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

1) Well, something in your code has almost certainly closed the statement or the connection (which will close the statement for you). There just isn't much else, assuming the code you posted is the code you used. Probably, your usage of the connection is not thread-safe in some way.

2) "Urgent" = "I'm new here and I don't have a clue but I want an answer right now!!!". There an unfortunately high correlation between the use of "Urgent" and ******* who are so irritating that I seriously reconsider how I spend my free time.

StuDerbya at 2007-7-13 18:54:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

> iate that and sorry for the word URGENT that is

> sensitive to you. I put the word in the subject line

> is because I have no choice but to attract good

> people like you's attentions on this issue.

If you feel that it is good to add that word, you might get flamed it in the near future. Most of the regulars dislike the use of that word, mainly because:

1. They have other work to do and responding to "URGENT" posts is not their priority.

2. What may appear urgent to you would be trivial to them.

3. If something is really urgent, this is not the best place to ask. You should search on Google or find some other developer with whom you could talk to.

> By the way, sorry to tell you that I'm quite new

> new to Java. What's so special about Runnable than

> extending Thread?

If you are extending a class, you are specializing the behaviour of the class. If your class has something special which when added to the default behaviour of the Thread class would result in a thread class with special behaviour, you should extend Thread by all means. If you are not making a speical kind of Thread class, there is no reason for the class to extend Thread because your class would NOT be a type of thread.

In such cases, you should implement Runnable. There is another advantage to implementing Runnable, you are free to let your class extend another class while allowing multi-threaded behaviour in your class.

aniseeda at 2007-7-13 18:54:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
Also, do not pass the ResultSet back if you are doing that.Collect the result set into a Collection that is not tied to the Connection and release that valuable resource as soon as possible (and in a threadsafe manner of course)
darteda at 2007-7-13 18:54:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
Ach! nvm not reading right....
darteda at 2007-7-13 18:54:47 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...