Robert
Robert

Reputation: 1638

JDBCTemplate INSERT INTO statement: Can't figure out error

I can't for the life of me figure out why the below query is returning this error message:

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;
 bad SQL grammar [INSERT INTO Survey (survey.PK1, survey.USERS_PK1, 
 survey.ACCREDITATION_PK1, survey.PRIVACY_TYPE_PK1, survey.EVAL_FORM_PK1,
 survey.TITLE, survey.DESCRIPTION, to_date(survey.START_DATE),
 survey.START_TIME, to_date(survey.END_DATE), survey.END_TIME,
 survey.HAS_GRADECENTER_COLUMN, survey.HAS_ANNOUNCEMENT )
VALUES(survey_SEQ.nextval,?,?,?,?,?,?,?,?,?,?,?,?)];
nested exception is java.sql.SQLSyntaxErrorException: ORA-00917: missing comma

 

    String sql = "INSERT INTO UHCL_PR_survey " +
            "(" +
            "PK1, " +
            "USERS_PK1, " +
            "ACCREDITATION_PK1, " +
            "PRIVACY_TYPE_PK1, " +
            "EVAL_FORM_PK1, " +
            "TITLE, " +
            "DESCRIPTION, " +
            "to_date(START_DATE), " +
            "START_TIME, " +
            "to_date(END_DATE), " +
            "END_TIME, " +
            "HAS_GRADECENTER_COLUMN, " +
            "HAS_ANNOUNCEMENT " +
            ") " + 
            "VALUES (UHCL_PR_survey_SEQ.nextval,?,?,?,?,?,?,?,?,?,?,?,?) ";

    Object[] parameters = new Object[]{
            survey.getUsersPk1(),
            survey.getAccreditationPk1(),
            survey.getPrivacyTypePk1(),
            survey.getFormTypePk1(),
            survey.getTitle(),
            survey.getDescription(),
            new java.sql.Date(survey.getStartDate().toDate().getTime()),
            survey.getStartTimeAsUtilString(),
            new java.sql.Date(survey.getEndDate().toDate().getTime()),
            survey.getEndTimeAsUtilString(),
            survey.getGradeCenterColumn(),
            survey.getAnnouncement()
    };
this.jdbcTemplate.update(sql, parameters);

Upvotes: 0

Views: 5672

Answers (1)

Luke Woodward
Luke Woodward

Reputation: 65044

Don't put to_date around the START_DATE and END_DATE in the column names in your INSERT statement.

For one thing, that part of the INSERT statement should only list the names of the columns. I suspect that the names of your columns are START_DATE and END_DATE, and that you don't actually have columns in your table called to_date(START_DATE) and to_date(END_DATE).

Secondly, you don't need TO_DATE anywhere in your INSERT statement. JDBC converts all Dates to the relevant DBMS-specific DATE type for you automatically.

Upvotes: 3

Related Questions