EJB design: How to Pass primitive type in Query.setParameter
I am developing an DB application where i need to update table having primitive type fields (Ex: int). Since the SQL Table has int/byte field type. Sample Code: ************ int salary = 200; sql1 = "update exployee where sal > ?1"; Query query1 = em.createNativeQuery(sql1); query1.setParameter(1, salary); The setParameter is not accepting int since there is not method in Query class. Also if i try to convert as integer object and try to update query1.setParameter(1 , new Integer(salary)); I am getting run time error like follows.. [IntegerType] could not bind value '200' to parameter: 2; [BEA][SQLServer JDBC Driver]Invalid parameter binding(s). Please help me to fix this. Thanks, Lakshmi
- Posted by: Lakshmi Narayanan
- Posted on: December 19 2007 09:41 EST
- Re: How to Pass primitive type in Query.setParameter by Krishna Pothula on December 25 2007 01:44 EST
query1.setParameter(1 , new Integer(salary));This is how you set Primitive Types in a prepared statement. It should work.. Pls check ur code again.