java - Spring JDBCTemplate Update issue -
in table definition, there column int data type. if value "0", want jdbctemplate update method update field "null" instead of "0" default.
this.jdbctemplate.update("update gcur_observation " + "set observerid = ?," + "observationdate = ?," + "pointcuring = ?" + " locationid = ? , observationstatus = 0", new object[] { new integer(newobservation.getobserverid()), newobservation.getobservationdate(), new integer(newobservation.getlocationid()) });
the code snippet above runs when point curing
not null
. however, how can stored null
in database table?
i hope getting null pointer exception.
try this
integer locid = null; if(newobservation.getlocationid() != null) { locid = new integer(newobservation.getlocationid()); if(locid == 0) { locid = null; } }
and pass locid here.
this.jdbctemplate.update("update gcur_observation " + "set observerid = ?," + "observationdate = ?," + "pointcuring = ?" + " locationid = ? , observationstatus = 0", new object[] { new integer(newobservation.getobserverid()), newobservation.getobservationdate(), locid) });
Comments
Post a Comment