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
Post a Comment