如何使用 EOD SQL 创建动态查询?

发布于 2024-08-07 19:43:38 字数 833 浏览 4 评论 0原文

这应该相当简单,尽管我似乎找不到一个例子。 我想创建一个如下所示的查询:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半岛未凉 2024-08-14 19:43:38

我建议查看 EoD SQL 2.0: https://eodsql.dev.java.net/
然后看一下专门针对这种情况设计的 QueryTool.select() 方法。

EoD SQL 0.9 没有内置的功能来处理此类查询。

一个非常丑陋的 hack 是创建一个临时表,并用数组数据填充它。然后运行查询:

@Select("SELECT storename FROM broadcastrecipient WHERE storecity IN (SELECT * FROM tmp_cities)")
public List<String> getStoresForCurrentCities();

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:

@Select("SELECT storename FROM broadcastrecipient WHERE storecity IN (SELECT * FROM tmp_cities)")
public List<String> getStoresForCurrentCities();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文