Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating null dates in DB2 using JSP

Status
Not open for further replies.

rk68

Programmer
Jul 15, 2003
171
0
0
IN
I am using JSP script which update/inserts some value into DB2, but getting error while doing the same.
The script is passing some values which uses the same in the update/insert SQL. The date value is initialized as null in a variable & this variable is called in the SQL statement. If the date is null it passes a null value & this gives error.
============
String Np1_dob = request.getParameter("p1_dob");

String UpdSql = "update db2admin.T_CUS_NAP set " ;
UpdSql = UpdSql + "(CUS_ORG, CUS_PTNR1_DOB, CUS_PTNR1_SPS_NM, CUS_PTNR1_SPS_DOB) = ('";
UpdSql = UpdSql + Ndname + "','" + Np1_dob + "','" + Np1_spnm + "','" + Np1_spdob +"'";
=================
The variable is p1_dob is initially passed as null. If contains a date then value is passed to Np1_dob (as shown above), then SQL works fine but if its a null value then gives error as the SQL passes the null value with quotes ('null') which is not accepted in DB2 for date values.
How do I get this done ?
Please Help.

TIA
Raj



 
String Np1_dob = (request.getParameter("p1_dob"))==null?"null":'request.getParameter("p1_dob")';

String UpdSql = "update db2admin.T_CUS_NAP set " ;
UpdSql = UpdSql + "(CUS_ORG, CUS_PTNR1_DOB, CUS_PTNR1_SPS_NM, CUS_PTNR1_SPS_DOB) = ('";
UpdSql = UpdSql + Ndname + "'," + Np1_dob + ",'" + Np1_spnm + "','" + Np1_spdob +"'";

That should work.


Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
My mistake..

The correct syntax should be:

String Np1_dob = (request.getParameter("p1_dob"))==null?"null":"'request.getParameter("p1_dob")'";

String UpdSql = "update db2admin.T_CUS_NAP set " ;
UpdSql = UpdSql + "(CUS_ORG, CUS_PTNR1_DOB, CUS_PTNR1_SPS_NM, CUS_PTNR1_SPS_DOB) = ('";
UpdSql = UpdSql + Ndname + "'," + Np1_dob + ",'" + Np1_spnm + "','" + Np1_spdob +"'";

Hope this helps.

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top