sql - Invalid character Exception when adding multiple parameters to NativeQuery -
i use jdbc
, want create nativequery
2 parameters, 1 of them string
, other 1 int
. when try this:
import javax.persistence.entitymanager; ... private final entitymanager entitymanager; .... string columnname = "examplename"; int columnnumber = 5; entitymanager.createnativequery("select c.table_name, c.tcl_number col_name c c.table_name " + "like ?1 , c.tcl_number ?2;") .setparameter(1, columnname) .setparameter(2, columnnumber) .getsingleresult();
i java.sql.sqlsyntaxerrorexception: ora-00911: invalid character
exception. sql:
create table col_name ( table_name varchar2(50 byte), table_number number(10,0) );
do have consider special when want set int
parameter?
as found out problem in query comes ?1
, ?2
. compiled like:
select c.table_name, c.tcl_number col_name c c.table_name 'val1'1 , c.tcl_number 'val2'2
which incorrect sql syntax.
so correct code be:
entitymanager.createnativequery("select c.table_name, c.tcl_number col_name c c.table_name " + "like ? , c.tcl_number = ? ") .setparameter(1, columnname) .setparameter(2, columnnumber) .getsingleresult();
Comments
Post a Comment