如何在sql Query中使用从executeWithArray(Object [])传递的数组

时间:2015-03-19 09:48:06

标签: jdo datanucleus

我使用executeWIthArray()来传递列表。但是,当我尝试在Query中使用此数组时,它显示错误。这是我的代码

QueryHelper.setSortOrderZero(pm).executeWithArray(list);

在QueryHelper中,我已经定义了函数setSortOrderZero,如下所示:

public static Query setSortOrderZero(PersistenceManager pm) {
final Query query =  pm.newQuery("javax.jdo.query.SQL","update TABLENAME set SORTORDER = 0 where ID in list");

return query;

}

但是我得到了错误。这是访问数组的正确方法????

ERROR:

   Exception in ProtectedFilter: Error executing SQL query "update    PROFILEARTADS set SORTORDER = 0 where PROFILE_ID in list".
  Mar 19, 2015 4:51:44 PM com.sun.jersey.spi.container.ContainerResponse    mapMappableContainerException
     SEVERE: The RuntimeException could not be mapped to a response, re-  throwing to the HTTP container
    javax.jdo.JDODataStoreException: Error executing SQL query "update PROFILEARTADS set SORTORDER = 0 where PROFILE_ID in list".
    at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:422)
    at org.datanucleus.api.jdo.JDOQuery.executeWithArray(JDOQuery.java:321)
    at com.giri.artsite.server.per.PersistenceDelegate.deleteAllArtsduplicate(PersistenceDelegate.java:8499)
    at com.giri.artsite.server.res.PersonServiceResource.deleteAllArts(PersonServiceResource.java:4681)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    NestedThrowablesStackTrace:
    com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in      your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'list' at line 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1585)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1500)
    at c

1 个答案:

答案 0 :(得分:0)

如上所述,在SQL a"参数"必须是"?"在查询中;你没有参数,所以没有点传递一些参数数组。 更有意义的是

q = pm.newQuery("javax.jdo.query.SQL", "update TABLENAME set SORTORDER = 0 where ID in ?");
List values = ...
q.execute(values);