raghu tammina wrote:
Yes i tested exact statement.
i got id=108.
That isn't the SQL statement generated by your code, the spacing and capitalization is wrong. I suggest you print out the generated statement and then cut and paste the output into whatever application you use to directly execute the sql.
Also you didn't answer my second question - have you tried outputting the value of ID to see if it really is 0.
Finally (and probably most importantly) do as Jaikiran has suggested and show the code for the DBHelper.getIntResult(..) method and also the code immediately following the code you have shown so we can see what you do with the returned id.
What I believe is happening is that the locale of the client you're using to test the query differs from the locale that your application is using. This could be true for various reasons (and I'm not going into it here, except to say that it happens). The problem then would be that date formatted in Java doesn't match the format the database expects, which leads either to errors (probably just ignored in your code) or wrong records being matched (if the database expect the date in the YYYY-DD-MM format and the day of month is less then 13, for example).
I'd suggest doing the following:
1) Modify your code to use prepared statements - this page has three very compelling reasons to do so, and the second reason is what I'm talking about. This should resolve your current problems.
2) Make sure that any exceptions in your code are not ignored. Exceptions must cause the current action to be aborted, must be shown to the user (so that the user knows something went wrong) and must be properly logged (a full stacktrace at the very very least), so that someone can actually try to nail them down when reported. This should help you resolve your future problems - there always are problems - faster.
Joined: Jul 11, 2012
I got id is zero i'm printing the value in stack trace.
The output you've posted seems to contain messages sent to stdout. However, e.printStackTrace() prints the stack trace to stderr. At this point I believe that you're getting an exception for reasons I've explained in my previous post.
Your getIntResult method will return zero even when an exception occurs, which you mistakenly interpret as a nonexistent record. You should propagate the exception higher up instead, since it is clearly a situation the application is not ready to deal with. I personally would throw an unchecked exception - say, a RuntimeException - as there is no way to recover from it and the sole purpose would be to abort current processing and log the exception at the topmost level. So, instead of I'd use