• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic