如何使用 EOD SQL 创建动态查询?
这应该相当简单,尽管我似乎找不到一个例子。 我想创建一个如下所示的查询:
SELECT column_name FROM table_name WHERE column_name IN (value1,value2,...)
作为一个选项,我可以将 OR 子句附加到查询的末尾。
到目前为止,我编写的代码不断因空指针而崩溃:
@Select(sql = "select storename from broadcastrecipient where storecity in (?{1})")
public List<String> getStoresForCities(List<String> theCities) throws SQLException;
提前致谢。 //Abean
注意:我忘记添加一些有关我的环境的信息:PostGres 8.3、Java 1.6 和 EOD SQL 0.9。
谢谢杰森。 对于那些想知道的人来说,查询看起来像这样:
@Select(sql = "select distinct(storename) from broadcastrecipient where storecity = any (?{1})", disconnected=true)
public List<String> getStoresForCities(String[] theCities) throws SQLException;
我还需要实现一个 TypeMapper 类来将 SQL 数组映射到 Java 数组。
This should be fairly simple, though I can't seem to find a single example.
I want to create a query looking like this:
SELECT column_name FROM table_name WHERE column_name IN (value1,value2,...)
As an option I could append OR-clauses to the end of the query.
The code I have written so far keeps blowing up with a Nullpointer:
@Select(sql = "select storename from broadcastrecipient where storecity in (?{1})")
public List<String> getStoresForCities(List<String> theCities) throws SQLException;
Thanks in advance.
//Abean
NOTE: I forgot to add some info about my env: PostGres 8.3, Java 1.6 and EOD SQL 0.9.
Thank you Jason.
For those who like to know, the query looks something like this:
@Select(sql = "select distinct(storename) from broadcastrecipient where storecity = any (?{1})", disconnected=true)
public List<String> getStoresForCities(String[] theCities) throws SQLException;
And I also needed to implement a TypeMapper class to map SQL-array to Java array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议查看 EoD SQL 2.0: https://eodsql.dev.java.net/
然后看一下专门针对这种情况设计的 QueryTool.select() 方法。
EoD SQL 0.9 没有内置的功能来处理此类查询。
一个非常丑陋的 hack 是创建一个临时表,并用数组数据填充它。然后运行查询:
I would suggest looking at EoD SQL 2.0: https://eodsql.dev.java.net/
Then take a look at the QueryTool.select() method which is designed exactly for this situation.
EoD SQL 0.9 has no functionality to cope with this sort of query built in.
A really ugly hack is to create a temp table, and populate it with your array data. Then run the query as: