0

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.

2
  • ps is inherited method that get String as query and next is used as parameter fo prepareStatement method Commented Feb 6, 2013 at 22:13
  • what is the full error message that you're getting? Commented Feb 6, 2013 at 22:17

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

2 Comments

but presentation_id is foreign key for presentation related to slide
I believe that presentation_id is not the pk of slide table.
0

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/

1 Comment

I know this method but I have to use this ps inherited method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.