Jboss-QL 中的动态sql查询问题

cnwy
02-09-02 9 451

如果我想拼语句,而不是传参数,对应日期类型,该怎么处理?

banq
2002-09-02 16:10

WHERE reservation.arrivalDate = ?1

传递的参数必须是Date

cnwy
2002-09-02 16:20

你这种方法是传参数,而我相直接拼语句,如
StringBuffer jbossQl = new StringBuffer();
jbossQl.append("SELECT OBJECT(g) ");
jbossQl.append("FROM gangster g ");
jbossQl.append("WHERE g.hangout.state ='1' and");
^^^我直接拼,不传参数了
jbossQl.append("g.hangout.begindate =??????");
^^^^^^^不会写

banq
2002-09-02 16:55

public abstract class GangsterBean implements EntityBean {
public abstract Set ejbSelectGeneric(String jbossQl, Object[] arguments)
throws FinderException;
public Set ejbHomeSelectInStates(Set states) throws FinderException {
// generate JBossQL query
StringBuffer jbossQl = new StringBuffer();
jbossQl.append("SELECT OBJECT(g) ");
jbossQl.append("FROM gangster g ");
jbossQl.append("WHERE g.hangout.state IN (");
for(int i = 0; i < states.size(); i++) {
if(i > 0) {
jbossQl.append(", ");
}
jbossQl.append("?").append(i+1);
}
jbossQl.append(") ORDER BY g.name");
// pack arguments into an Object[]
Object[] args = states.toArray(new Object[states.size()]);
// call dynamic-ql query
return ejbSelectGeneric(jbossQl.toString(), args);
}
}

<jbosscmp-jdbc>
<enterprise-beans>
<entity>
<ejb-name>GangsterEJB</ejb-name>
<query>
<query-method>
<method-name>ejbSelectGeneric</method-name>
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.Object[]</method-param>
</method-params>
</query-method>
<dynamic-ql/> <!--注意这里的!!!!!-->
</query>
</entity>
</enterprise-beans>
</jbosscmp-jdbc>

banq
2002-09-02 16:57

上面的
if(i > 0) {
jbossQl.append(", ");
}
jbossQl.append("?").append(i+1);
}
是否符合你的需要?

2Go 1 2 下一页