This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
In SQL null never equals anything, even another null. I haven't used prepared statements enough to know whether it would throw an exception for an invalid condition, convert the syntax to "is null", or just return, um, what did you get back?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Mar 15, 2006
That I have to verify whether rs is null or not. I am using JTEST. And JTEST is passing null as argumnet to the method and asking me assertNotNull (the return)???
Joined: Jan 29, 2003
Did you write the test? If so you can change it to test for another return value if the null turns out to not work. If you can't change it (maybe it's an existing API or a class assignment?) you'll probably have to do something to make it pass.
Have you run the code snippet you showed? What actually came back?
Originally posted by Arun Thakur: That I have to verify whether rs is null or not.
Why? The documentation for Statement's executeQuery method specifically says that it will never return null. And what does that test have to do with whether a bind variable in a PreparedStatement being null?
It sounds like JTest is passing null to the method, not the result set. This is to get you think about what should happen if null is passed. Should the code throw an IllegalArgumentException, pass silently, etc. Or if it could never happen, you can supress the test.
I would throw an exception rather than call setString with a null through - for the reasons others have described above.
For those following this, JTest is a commericial tool that checks coding conventions and tries to generate tests that will break your code.
If this thread moves back to the topic of testing, we can move it back to the testing forum for you. If it stays related to JDBC, it can stay here.