users@glassfish.java.net

pass primitive type in Query.setParameter

From: <glassfish_at_javadesktop.org>
Date: Tue, 18 Dec 2007 13:59:39 PST

I am developing an DB application where i need to update table having primitive type fields (Ex: int).

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
[Message sent by forum member 'laknarayan' (laknarayan)]

http://forums.java.net/jive/thread.jspa?messageID=250651