添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I need to form an query in JPQL (2.0) to select a the max value (rank).

I use: SELECT max(rank) FROM test

This works fine, except the case where the table is empty, then the result is null , but I need 0 .

This would be no problem if I was able to "catch" the null with an simple if-statement, but I can't do this (the framework allows only to specify an JPA Query but no java code).

Does anybody have an idea how to tune that query to get an 0 instead of an null if the table is empty? - The database is an MySQL, and native queries or stored procedures are no option.

No native queries, no stored proc, you can't do a simple if (ret == null) ret = 0; kind of thing. I'm curious, why all the restrictions? Feels like you are deliberately tying your hands behind your back. pap Apr 19, 2012 at 9:25

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .