GQL error on WHERE

2019-09-05 00:03发布

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

I get exception:

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

While this query works nice:

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

And this too:

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

The full code:

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

1条回答
何必那么认真
2楼-- · 2019-09-05 00:56

Replace "AND" with "&&"

  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();
  }
查看更多
登录 后发表回答