persistence@glassfish.java.net

Re: SQL Parameter Binding - how to enable?

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Thu, 14 May 2009 10:15:33 -0300

The parameter value you are passing to the query is "Tank00000001" but
when you write the SQL yourself you are using "Tank00000000". Are you
sure data exists for when the parameter is "Tank00000001"?
--Gordon

yonestar wrote:
> Hello,
>
> I can't seem to get parameter binding to work! Does it need to be enabled?
> I am using Glassfish, Toplink, NetBeans, and Derby -- the standard NetBeans
> package.
>
> MY JAVA:
> StringBuffer sql = new StringBuffer("SELECT * FROM container WHERE contid =
> ?1 AND ...... ");
> em.createNativeQuery(sql.toString(), Container.class).setParameter(1,
> "'"+contid+"'").getResultList();
>
> MY PERSISTANCE.XML:
> <property name="toplink.bind-all-parameters" value="true"/>
> <property name="toplink.jbdc.bind-parameters" value="true"/>
>
> SQL THAT GETS EXECUTED:
> SELECT * FROM container WHERE contid = ? AND siteid = 'YoniCntr' AND
> subcontid > 0 ORDER BY subcontid ASC
> bind => ['Tank00000001']
>
>
> And I get no results!
> I have written the exact same query without parameter binding, which gets
> executed like
> SELECT * FROM container WHERE contid = 'Tank00000000' AND siteid =
> 'YoniCntr' AND subcontid > 0 ORDER BY subcontid ASC
>
> And results do return!
>
> Please advise, many thanks!
>