UsingJava 1.8
andSpring Framework 4.0.3-RELEASE
, I am trying to insert a row into a MySQL database after getting a value from an external source.
Try this:
private static JdbcTemplate jdbcTemplateObject = null; private static final String INSERT_QUERY = "insert into order_table(id,order_id,created_time,updated_time)VALUES(?,?,now(),now())"; parseFeedAndStoreIntoDB() { List
When I run this method, I get the following exception:
Exception in parseFeedAndStoreIntoDB() method org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [insert into order_table(id,order_id,created_time,updated_time)VALUES(?,?,now(), now());]; Parameter index out of range (4 > 3).; nested exception is java.sql.SQLException: Parameter index out of range (4 > 3).
I have counted the number of rows, there are 4 rows in both my Java code and the MySQL database table I created.
Your query has bind parameters on
id
andorder_id
, the other two fields are set tonow()
in the query. Willchanged to
orwill be
changed to