ERROR java.sql.SQLException: ORA-01722: invalid number while running a Prepared Statement to alter a Sequence

smriti picture smriti · Apr 30, 2011 · Viewed 9.1k times · Source
sqlStmt = new StringBuffer("  ALTER SEQUENCE "  );  
                    sqlStmt.append( ServerContext.getSchemaName() );
                    sqlStmt.append("SEQ_EDCD_TRACE_NUM");
                    sqlStmt.append( " INCREMENT BY " );
                    sqlStmt.append( " ? " );
pstmt.setLong(1, incval);
pstmt.execute();

Answer

Luke Woodward picture Luke Woodward · Apr 30, 2011

You can't use bind variables with DDL, such as ALTER SEQUENCE. You'll have to concatenate incval onto the string.

There shouldn't be any risk of SQL injection if incval is an int or a long.