java - How do I send a null variable, instead of a blank one to my sql DB? -


whenever tries register using program, , leaves non-required textfield blank, instruction sends "" (blank) data, instead on null one, how make data i'm inserting null whenever textfield blank? thanks

if you're using raw sql:

insert mytable values ('foo', null, 'bar') 

if you're using prepared statements:

preparedstatement.setobject(columnindex, null); 

using query comment, here's simple fix: apply replaceall() change blanks null, this:

st.executeupdate("insert clientes (nombre, telefono, calle, numero,colonia, municipio, estado, codigo_postal,sexo,fecha_nacimiento) values ('"  + snombre_cliente + "','" + stelef_cliente + "','" + scalle + "','" + snumero + "','" + scolonia + "','" + smunicipio + "','" + sestado + "','" + scodigop + "','" + ssexo + "','" + sfecha  + "')".replaceall("'\\s*'", "null")); 

this replace quotes separated number of spaces (including no spaces) word "null".


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -