wood burning stoves 2.0*
The moose likes JDBC and the fly likes prepared statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "prepared statement" Watch "prepared statement" New topic
Author

prepared statement

rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
i am using following code but if condition is not working .....values are coming from previous servlet if i dont enter any value for i2 and i3 then the value of m2 and m3 will be null but statements in second and third if condition are being executed...please help me to solve this problem

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Most likely m2 and m3 are NOT null; their value is probably the zero-length string.
rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
Tim Moores wrote:Most likely m2 and m3 are NOT null; their value is probably the zero-length string.

but when i try to print thees values .null value is printed so what should i do for this ....i dont want to print all the three if condition .depends on values of i1,i2 and i3 entered from previous servlet
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
That sounds unlikely. We don't know how you print the values, but if the value of m1 is null, then a block guarded by "if (m1!=null)" wouldn't be executed.

Your variable names are very confusing, by the way - m1, n1, o1 means nothing. Why aren't they named i1, q1, c1 to go along with the parameter names? Or, even better, have a name that actually describes what they contain?

There's no point in loading the DB driver every single time the servlet is accessed, by the way. You should move that code to the init method.
rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
Tim Moores wrote:That sounds unlikely. We don't know how you print the values, but if the value of m1 is null, then a block guarded by "if (m1!=null)" wouldn't be executed.

Your variable names are very confusing, by the way - m1, n1, o1 means nothing. Why aren't they named i1, q1, c1 to go along with the parameter names? Or, even better, have a name that actually describes what they contain?

There's no point in loading the DB driver every single time the servlet is accessed, by the way. You should move that code to the init method.


i will chage variable name .but i think it is not releted to my problem ...i am printing the value of m2 amd m3 in next page by redirecting the servlet to next page only for checking their values....i am confused that where am i wrong ???
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 80
try with this StringUtils class.

if(!StringUtils.isEmpty(s1))
{

}

if s1 is null or empty String.it will work.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

rakhi sinha wrote:
Tim Moores wrote:That sounds unlikely. We don't know how you print the values, but if the value of m1 is null, then a block guarded by "if (m1!=null)" wouldn't be executed.

Your variable names are very confusing, by the way - m1, n1, o1 means nothing. Why aren't they named i1, q1, c1 to go along with the parameter names? Or, even better, have a name that actually describes what they contain?

There's no point in loading the DB driver every single time the servlet is accessed, by the way. You should move that code to the init method.


i will chage variable name .but i think it is not releted to my problem ...i am printing the value of m2 amd m3 in next page by redirecting the servlet to next page only for checking their values....i am confused that where am i wrong ???

changing the names will not solve your problem... but it will mean that it is easier to read your code and understand it, and when you have to come back to maintain this code later you will understand what it is doing.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

rakhi sinha wrote:
Tim Moores wrote:Most likely m2 and m3 are NOT null; their value is probably the zero-length string.

but when i try to print thees values .null value is printed so what should i do for this ....i dont want to print all the three if condition .depends on values of i1,i2 and i3 entered from previous servlet


do they actually contain the word 'NULL'?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
rakhi sinha wrote:i am printing the value of m2 amd m3 in next page by redirecting the servlet to next page only for checking their values

If you do a redirect then all your parameters will be gone, so that's not a valid test. You might want to consider using a debugger to step through the actual code that causes the problem.
 
 
subject: prepared statement
 
Similar Threads
How to configure Bonecp in java project without breaking connection when more than connection
how to update data of a field in one table from other table using jsp or java?
insertion of values
prepared statement
doubt regarding default values