• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLRecoverableException: No more data to read from socket

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Full Stack Trace:


Here is my code. Please advise whats going on wrong with my code:



Thanks an anticpation

Best regards
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this error occur randomly, or every time you run the code?

In the first case, it might be a networking glitch. In the second case, it might be a bug in the JDBC driver (yes, there are occasionally some); I'd suggest to try using a different version of the driver (see our Oracle FAQ).

I'd also advice against using this
Firstly, you're catching an Exception, which is too broad. Your code can only throw SQLException, and you should only catch that. If you modify your code in the future in a way it could throw a different checked exceptions, your catch clause might start handling exceptions you haven't intended when you wrote the code.

Secondly, an exception should end the processing. You simply return false when an exception occurs, but you cannot know the nature of the exception, and in most cases, when an SQLException occurs, you can't tell anything about the state of the database connection which was used at that time. You should simply cancel the rest of your processing, probably by throwing out some unchecked exception (a RuntimeException, for example). That exception should make it to some topmost level of your application, where it would be logged.

And finally, your method uses throws SQLException declaration, although, as far as I can tell, it cannot produce one (you're handling it within the method). This forces you to handle the SQLException in the caller. Simply drop the throws SQLException from the declaration.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Vajsar wrote:Does this error occur randomly, or every time you run the code?
And finally, your method uses throws SQLException declaration, although, as far as I can tell, it cannot produce one (you're handling it within the method). This forces you to handle the SQLException in the caller. Simply drop the throws SQLException from the declaration.


Thanks for your favorable reply. dropping SQLException from the declaration fixed the problem

Thanks again & best regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic