如何在 sql 查询中使用从 executeWithArray(Object[]) 传递的数组
How to use array passed from executeWithArray(Object[]) in sql Query
我正在使用 executeWIthArray() 传递列表。但是当我尝试在查询中使用这个数组时,它显示 error.This 是我的代码
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.So 这是访问数组的正确方法吗????
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
如前所述,在 SQL 中,"parameter" 必须是“?”在查询中;你没有参数,所以没有必要传入一些参数数组。
更有意义的是
q = pm.newQuery("javax.jdo.query.SQL", "update TABLENAME set SORTORDER = 0 where ID in ?");
List values = ...
q.execute(values);
我正在使用 executeWIthArray() 传递列表。但是当我尝试在查询中使用这个数组时,它显示 error.This 是我的代码
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.So 这是访问数组的正确方法吗????
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
如前所述,在 SQL 中,"parameter" 必须是“?”在查询中;你没有参数,所以没有必要传入一些参数数组。 更有意义的是
q = pm.newQuery("javax.jdo.query.SQL", "update TABLENAME set SORTORDER = 0 where ID in ?");
List values = ...
q.execute(values);