是否有任何库重新present SQL查询中的Java code对象? [英] Is there any library to represent SQL queries as objects in Java code?

查看:106
本文介绍了是否有任何库重新present SQL查询中的Java code对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想,如果有,可以用来重新present SQL查询中Java对象的库。

在code我有很多是手写的SQL查询java.lang.String类型的静态变量。我要寻找有一个很好的图书馆精通的API,可以让我重新present查询的对象而不是字符串。

例如:

 查询Q =选择(DATE,QUOTE)
  。从(股市)
  。凡(当量(CORP。,?))
  .orderBy(DATE,DESC);


解决方案

JEQUEL看起来pretty俏皮: HTTP://www.jequel。德/

它采用了流畅的界面,所以很容易阅读,就像天然SQL(从文档):

 的SqlString SQL =选择(ARTICLE.OID)
               。从(物品,ARTICLE_COLOR)
               。凡(ARTICLE.OID.eq(ARTICLE_COLOR.ARTICLE_OID)
               。而(ARTICLE.ARTICLE_NO.is_not(NULL)));

它也支持执行查询对带参数的数据源,所以它处理参数化查询的创作也是如此。

I was wondering if there is any library that can be used to represent SQL queries as objects in Java.

In the code I have plenty of static variables of type java.lang.String that are hand written SQL queries. I would be looking for library having a nice fluent API that allows me to represent the queries as objects rather than strings.

Example:

Query q = select("DATE", "QUOTE")
  .from("STOCKMARKET")
  .where(eq("CORP", "?"))
  .orderBy("DATE", DESC);

解决方案

Jequel looks pretty nifty: http://www.jequel.de/

It uses a fluent interface, so it's easy to read, almost like natural SQL (from the docs):

SqlString sql = select(ARTICLE.OID)
               .from(ARTICLE, ARTICLE_COLOR)
               .where(ARTICLE.OID.eq(ARTICLE_COLOR.ARTICLE_OID)
               .and(ARTICLE.ARTICLE_NO.is_not(NULL)));

It also supports executing queries against a DataSource with parameters, so it handles creation of parameterized queries as well.

这篇关于是否有任何库重新present SQL查询中的Java code对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆