tooki
asked on
NULL value problem (URGENT please!)
From my JSP program I need to execute an SQL insert statement:
***JSP file**
<%
String st1;
...
...//some work done on st1
..
count = stmt.executeUpdate("insert into mytab (f1, f2,..) values ('st1', ...,..)");
Here when I execute above statement, I do not know if string "st1" has some value or if it is null. If "st1" has some value, no problem.But if "st1" has no value, the above statement is entering the string "nu;;" in the above table:
SQL>select f1 from mytab:
f1
==
null
How can I change my JSP to avoid entering "null" when st1 does not have any content?
please help!
***JSP file**
<%
String st1;
...
...//some work done on st1
..
count = stmt.executeUpdate("insert
Here when I execute above statement, I do not know if string "st1" has some value or if it is null. If "st1" has some value, no problem.But if "st1" has no value, the above statement is entering the string "nu;;" in the above table:
SQL>select f1 from mytab:
f1
==
null
How can I change my JSP to avoid entering "null" when st1 does not have any content?
please help!
ASKER
Thanks!
But is was ok if I was ambigupus about only one field (if it is null) in that satement. but if in the insert sql statement has say 5 fields and I know that any of them can be null, then it becomes difficult.
And when a string is null, I would like to enter no value (In oracle it is NULL) for that field insead of the string "null".
Isn't there any better way of this null check?just wonder..
-tooki
But is was ok if I was ambigupus about only one field (if it is null) in that satement. but if in the insert sql statement has say 5 fields and I know that any of them can be null, then it becomes difficult.
And when a string is null, I would like to enter no value (In oracle it is NULL) for that field insead of the string "null".
Isn't there any better way of this null check?just wonder..
-tooki
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if (st1 == null)
count = stmt.executeUpdate("INSERT
else
count = stmt.executeUpdate("INSERT
And I would suggest using PreparedStatement instead:
PreparedStatement st = conn.prepareStatement("INS
st.setString(1,st1);
st.setString(2,...);
count = st.executeUpdate();
Regards!