Getting SQL errors with prepared statement in JDeveloper 10.1.3.2

I'm using oracle JDBC driver and I connect and update just fine from the SQL Worksheet in JDeveloper.
1) When I have more than 1 placeholder in my SQL statement, the last one is dropped so I get "Invalid column index".
2) When I add an extra one, it prepares OK but gets "ORA-01745: invalid host/bind variable name" on execution if the placeholder is inside the SQL closing paren (this situation is showed below).
3) When an extra one is outside the SQL closing paren, I get "ORA-00933: SQL command not properly ended"
I'm probably missing something obvious but here is the code I'm using:
public void insertToDB(Comment inrecord) throws Exception {
int idx = 0;
try {
this.initialize();
pstmt = conn.prepareStatement(
"INSERT INTO COMMENTS (COMMENT_ID, " +
"LOG_BUS_PROC_CDE, TYPE_CDE, SUBTYPE_CDE, " +
"REF_TYP_CDE, CREATE_USER, CREATE_DATE, " +
"UPDATED_USER, UPDATED_DATE, COMMENT_TEXT) VALUES(" +
"TO_TIMESTAMP('?','YYYY-MM-DD HH24:MI:SS.FF3'), ?, ?, " +
"?, ?, ?, TO_DATE(?,'MM/DD/YYYY'), NULL, NULL, ? ?)");
pstmt.setString(++idx,inrecord.getCommentID());
pstmt.setString(++idx,inrecord.getLogBusProcCDE());
pstmt.setString(++idx,inrecord.getTypeCDE());
pstmt.setString(++idx,inrecord.getSubTypeCDE());
pstmt.setString(++idx,inrecord.getRefTypCDE());
pstmt.setString(++idx,inrecord.getCreateUser());
pstmt.setString(++idx,inrecord.getCreateDate());
pstmt.setString(++idx,inrecord.getCommentTXT());
pstmt.executeUpdate();
conn.commit();
this.terminate();
catch (Exception e) {
conn.rollback();
this.terminate();
throw e;
}

Hi,
actually you increment the index
pstmt.setString(++idx,inrecord.getCommentID());
which means you never have an index of 0 but always start with 1
Frank

Similar Messages

Maybe you are looking for