adaniluk
adaniluk

Reputation: 431

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.

Upvotes: 0

Views: 775

Answers (2)

max246
max246

Reputation: 618

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/

Upvotes: 0

PermGenError
PermGenError

Reputation: 46438

dont include the auto inc fieldin your column list.

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

Upvotes: 1

Related Questions