简体   繁体   中英

error java.sql.SQLException: Parameter index out of range

I still get error that I don't provide value for 1 parameter and I don't have idea what is wrong.

ps("INSERT INTO slide (presentation_id, duration, position, type) values (?, ?, ?, ?)     ").set(this.getId()).set(slide.getDuration()).set(slide.getPosition()).set(slide.getType().ordinal()).update();

In table I only do not provide value for one column for which autoincrement is set.

Everything seems alright for me but please give any advice what might be wrong.

不要在列列表中包含auto inc字段。

ps("INSERT INTO slide (duration, position, type) values (?, ?, ?)     ").set(slide.getDuration()).set(slide.getPosition()).set(slide.getType().ordinal()).update();

Try to do something more clean instead of this "train code"

This is an example:

String insertTableSQL = "INSERT INTO DBUSER"
        + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE) VALUES"
        + "(?,?,?,?)";
PreparedStatement preparedStatement = dbConnection.prepareStatement(insertTableSQL);
preparedStatement.setInt(1, 11);
preparedStatement.setString(2, "mkyong");
preparedStatement.setString(3, "system");
preparedStatement.setTimestamp(4, getCurrentTimeStamp());
// execute insert SQL stetement
preparedStatement .executeUpdate();

and here is the link to follow: http://www.mkyong.com/jdbc/jdbc-preparestatement-example-insert-a-record/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM