user1836155
user1836155

Reputation: 918

SQL Builders in Java

I am currently shopping around for SQL builders in Java. My basic desire is something like this:

SelectBuilder sb = new SelectBuilder(source, alias); // Source can be subquery
sb.select(column1, alias1);
sb.select(column2, alias2);
sb.joinWith(joinObj, joinAlias);
sb.where(column1, operator, value)
sb.orderBy(column1, DESC)
// etc etc etc

... and that it does prepared statements

I've looked into JOOQ and my impression is that it is too convoluted for my taste. I don't want to set up some xml or xsd file for my schemas. The most I'd allow is to write the beans. I've looked at Squiggle but it only supports SELECT and not the rest. MyBatis is not good enough because it does not fully abstract out the SQL syntax. I've also tried several more recommended by Stack Overflow posts like this and that.

One additional thing that I really don't like about several Java-based SQL builder is the chaining syntax: i.e. select().from().where().etc().etc().etc()

Anyway, do you guys know of other SQL Builders that may meet my requirements? I've searched two days on web and couldn't find anything yet. Insight would be appreciated!!!

Upvotes: 2

Views: 1594

Answers (2)

Lukas Eder
Lukas Eder

Reputation: 220842

I've looked into JOOQ and my impression is that it is too convoluted for my taste

What does that even mean? :)

I don't want to set up some xml or xsd file for my schemas

You don't have to. You can use jOOQ without the code generator as documented here: https://www.jooq.org/doc/latest/manual/getting-started/use-cases/jooq-as-a-standalone-sql-builder

However, you will be missing out on tons of useful features if you don't use the code generator. How's the saying? Hours of writing code manually saves seconds of setting up the code generator. For even more convincing arguments about why you should use the code generator, read this article here.

One additional thing that I really don't like about several Java-based SQL builder is the chaining syntax: i.e. select().from().where().etc().etc().etc()

Why not? It really helps. But then again, you don't have to. jOOQ has 2 APIs. The DSL API (which you don't like) and the model API. See this page here: https://www.jooq.org/doc/latest/manual/sql-building/sql-statements/dsl-and-non-dsl

Upvotes: 12

Priit
Priit

Reputation: 480

Take a look at these:

http://www.querydsl.com/

https://github.com/ivanceras/fluent-sql

Also Hibernate Criteria API has fluent interface. To my experience if the query is anything more complicated than select from sometable then these fluent api-s make sql very unreadable.

Upvotes: 1

Related Questions