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!!!

Answers


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.

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


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.


Need Your Help

lua - capturing variable assignments

class lua oop metaprogramming

Ruby has this very interesting functionality in which when you create a class with 'Class.new' and assign it to a constant (uppercase), the language "magically" sets up the name of the class so it

JAXB Umarshaller error

java xml jaxb xsd jersey

I am trying to generate Object from XML using JAXB. First, I created the objects out of supplied schema and packaged them into 1 .jar. Now I am using this simple test program (after it refused to w...