This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What causes a SQLException?

 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone point me to a good reference on the possible causes of a SQLException? I've checked the JLS and javadoc, but the most specific information I'm able to find is the methods that throw SQLExceptions - I need to know why they throw exceptions. For many of the methods listed, this isn't clear to me.
I need to create unit tests for classes in a large application. The way the application has been structured, it generates a unique status code at every step. Hence, I've been tasked with figuring out under which circumstances specific status codes resulting from a SQLException will be generated.
Even a list of the most common cause of a SQLException would be a great help.
Thanks,
g.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These exceptions are one of my biggest complaints with JDBC, a SQLException is almost anything.
It can be:
thrown if you try to execute poor SQL
thrown if a table or attribute doesn't exist
thrown if the user has wrong DB privelidges
and bunches more.
Essentially its anything that can go wrong on the database side.
Often the only way to tell the difference is by looking at the message, but that leads towards parsing the messages to determine the messages thrown, which is inherantly dangerous...
But I digress.
Dave
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
From what you've said, it sounds like a SQLException would not generally be thrown because of bad input. Is that true? For instance, if I send a method a null in place of an expected argument and that null is used as a key in the SQL statement, will that throw a SQLException, a NullPointerException, or simply return an empty recordset?
Thanks!
g.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!