0
select from comments.Comment 
where ownerType == 'looks.Look' 
AND ownerName == 'Yakuza' order by date

我得到例外:

Portion of expression could not be parsed: AND ownerName == 'Yakuza'

虽然这个查询很好用:

select from comments.Comment 
where ownerType == 'looks.Look' 
order by date

这也是:

select from comments.Comment 
where ownerName == 'Yakuza' order by date

完整代码:

PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "... query goes here ...";
List<Comment> comments = null;
try {
    comments = (List<Comment>) pm.newQuery(query).execute();
}
...
4

1 回答 1

2

将“AND”替换为“&&”

  PersistenceManager pm = PMF.get().getPersistenceManager();
  try {
    Query query = pm.newQuery("select from " + Song.class.getName()
        + " where mArtist== '" +artist+
        "' &&  mTitle=='"+title+
        "' &&  mAlbum=='"+album+"'" );
    List<Song> list = (List<Song>) query.execute();
  } catch (RuntimeException e) {
    System.out.println(e);
    throw e;
  } finally {
    pm.close();
  }
于 2011-09-20T22:01:13.863 回答