Code:
public int addComment(final int recipeId, final String author,
final String comment) {
SqlUpdate sql = new SqlUpdate(ds,
"INSERT INTO comment " +
"(author, comment, recipe_id) " +
"VALUES (?,?,?)",
new int[] {Types.VARCHAR,Types.VARCHAR,Types.INTEGER});
KeyHolder keyHold = new GeneratedKeyHolder();
sql.update(new Object[] {author, comment, recipeId}, keyHold);
return keyHold.getKey().intValue();
}
In fact, when I run that code I get a debug level log message that says, "[org.springframework.jdbc.core.JdbcTemplate] - <SQL update affected 1 rows and returned 1 keys>"
Code:
public void insertParking(final Parking park) {
SqlUpdate sql = new SqlUpdate(ds,
"INSERT INTO parking " +
"(source,location_number,name,street_address,city,state," +
"county,zip_code,facility_telephone,country,number_of_spaces," +
"valet_spaces,monthly_spaces,latitude," +
"longitude,route_name) " +
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
new int[] {Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
Types.INTEGER,Types.INTEGER,Types.INTEGER,Types.DOUBLE,
Types.DOUBLE,Types.VARCHAR,});
KeyHolder keyHold = new GeneratedKeyHolder();
sql.update(new Object[] {
park.getSource(),
park.getLocationNumber(),
park.getName(),
park.getAddress(),
park.getCity(),
park.getState(),
park.getCountry(),
park.getZipCode(),
park.getFacilityTelephone(),
park.getCountry(),
park.getNumberOfSpaces(),
park.getValetSpaces(),
park.getMonthlyNumberOfSpaces(),
park.getLatitude(),
park.getLongitude(),
park.getRouteName()
}, keyHold);
return keyHold.getKey().intValue();
}
When I run this code, I get a NullPointerException at the line that contains the return statement and a debug level log message that says, "[org.springframework.jdbc.core.JdbcTemplate] - <SQL update affected 1 rows and returned 0 keys>"