whiteeagl
asked on
Form: Empty String instead of Null (Struts/Java)
Hi,
I have a web application based on struts framework. My database table has some required fields and some nullable. The problem I have is if I leave the field in my web form empty, the application inserts an empty string (varchar) instead of a null value.
How can I prevent the web application from converting the empty form fields to and empty string? I really need the fields to stay "NULL".
I am using stuts & validator, velocity and hibernate
thanks.
I have a web application based on struts framework. My database table has some required fields and some nullable. The problem I have is if I leave the field in my web form empty, the application inserts an empty string (varchar) instead of a null value.
How can I prevent the web application from converting the empty form fields to and empty string? I really need the fields to stay "NULL".
I am using stuts & validator, velocity and hibernate
thanks.
woops - this is in ASP code, but you should get the general idea.
insert NULL
not "NULL"
insert NULL
not "NULL"
ASKER
Thanks, but I was thinking more of a configuration issue. Just prevent null from being converted to an empty string in the first place.
Any ideas?
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just check your values first :
dim queryPhone
If Request("txt_Phone") <> "" Then
queryPhone = " ' " & Request("txt_Phone") & " ' " <--added quotes around the value
Else
queryPhone = "NULL" <-- no quotes around NULL
End If
mystring = "INSERT INTO MyTable(Name, Address, Phone) Values ('Bob', NULL, "& queryPhone &")"