javaoracle-databaseoracle11gapache-commons-dbutils

Commons DBUtils Oracle 11g Prepared Statement


im working with oracle database 11g release 2, and im using apache commons dbutils v1.6, with JDK 8 and tomcat 8.0.30. so im using the QueryRunner and its method and everything works fine if i just concat my variables in text like this

query.query ("select * from table where field = '"+value+"'", rsh);

lately i have been trying to do the query the proper way using prepared statements but to no avail, every time i bind parameters using the query method

query.query ("select ESTREC,LOTE,FECREC from prueba.RECAUDO_ENC where NITREC = ? and ESTREC = ? ORDER BY FECREC DESC", rsh, new Object[]{"1234","PG"}); 

i get this error for no aparent reason

java.sql.SQLException: ORA-00942: table or view does not exist
  Query: select ESTREC,LOTE,FECREC from prueba.RECAUDO_ENC where NITREC = ? and ESTREC = ? ORDER BY FECREC DESC; Parameters: [1234, PG]

im a 100% sure that the table exists, and user has permissions to the table , also if i do the same query concatenating the params in the query it runs just fine, so im looking for reasons behind this behaviour, is there something wrong in the usage of the method?. also i have read somewhere that there is some problem with BLOB binding using dbutils with oracle, could this be related in someway?


Solution

  • Correct query syntax for oracle is:

    query.query ("select ESTREC,LOTE,FECREC 
                    from prueba.RECAUDO_ENC 
                   where NITREC = :P1 and ESTREC = :P2 
                   ORDER BY FECREC DESC", 
                 rsh, new Object[]{"1234","PG"});