Link to home
Start Free TrialLog in
Avatar of whiteeagl
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.
Avatar of ThinkPaper
ThinkPaper
Flag of United States of America image

For mySQL, you can keep your field null by explicitly inserting the NULL value..

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 &")"

woops - this is in ASP code, but you should get the general idea.

insert NULL
not "NULL"
Avatar of whiteeagl
whiteeagl

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?
ASKER CERTIFIED SOLUTION
Avatar of Greyz
Greyz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial