我正在使用jdbcTemplate的準備語句將一些數據寫入表中。目前,我正面臨以下例外情況,我不確定我做錯了什麼。使用PreparedStatement插入數據的JdbcTemplate更新的異常
private void insertdata(String time, String data, Datasource datasource){
String sql = "insert into table1 (columns1, columns2) values (:time, :data)";
jdbcTemplate jdbctemplate = new jdbcTemplate(datasource);
Object[] params = {time, data};
int[] types = {Types.VARCHAR, Types.VARCHAR};
try{
jdbctemplate.update(sql, params, types);
}catch(Exception e){
//some error handling
}
}
我在日誌中看到以下異常。
PreparedStatementCallback; SQL [insert into table1 (columns1, columns2) values (:time, :data)]; Parameter index out of range (1 > number of parameters, which is 0).; nested exception is java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
我不知道我在哪裏犯了一個錯誤。
你爲什麼不使用'SqlMapParamSource'錯誤(?,?)? – TheLostMind