Hi Paul, Lukas from Data Geekery here (the company behind jOOQ).
Java is indeed a very interesting ecosystem where there have always been dozens of alternative ways to do the same thing. This happens when a platform vendor (Oracle) does not provide out-of-the-box solutions for most standard use-cases, e.g. the way Microsoft does on the .NET platform. Just check out how many web frameworks there are...
In our opinion, there are at least three very distinct ways of talking to the database from any client language like Java:
Using ORMs
When you're using an ORM, you probably don't care about querying as much as you care about persisting your objects, possibly a graph of objects. ORMs do this pretty well. They mostly help you pretend you don't need SQL in your everyday work. This is great for small projects, and for complex conversations with the database.
Among the APIs you've listed, this category would include:
- Hibernate
- JDO
- JPA (of which Hibernate is an implementation)
Using externalised SQL
Sometimes (in our opinion very often), an ORM doesn't do the job for you because you want to get down to the metal writing actual SQL, e.g. for reporting, analytics, bulk/batch data processing, or just for the odd query that is sligthly more complex than what an ORM can offer. When you do that, you have two choices: embedding your SQL in your Java classes, or externalising it. iBatis (nowadays called MyBatis) is the only popular API in this field (although jOOQ can do this as well):
- iBATIS / MyBatis
Using embedded SQL
jOOQ mostly fits the "embedded SQL" API category. In this category, you want your SQL statements close to your "other" data access logic: Your DAOs, your services, etc.
Among the APIs you've listed, the following fit this category:
- Spring (with JdbcTemplate)
- jOOQ
There is also:
- plain
JDBC, of course
What jOOQ offers uniquely, unlike any other framework, is compile-time type safety for all your SQL statements. The Java compiler will type-check not only your SQL syntax for you, but also your tables and columns and their respective data types, as a source code generator will generate those objects for you, automatically. This goes further: Since you're constructing the AST (Abstract Syntax Tree) of your SQL statement dynamically at runtime, you also benefit from awesome features like:
- Dynamic SQL composition (you can store parts of your SQL statement and reuse it many times, e.g. a common predicate)
- SQL injection prevention (jOOQ forces you to use bind variables, without you actually noticing)
- SQL transformation capabilities (e.g. you can generate different SQL statements depending on your session, e.g. for security reasons)
- SQL standardisation (the same SQL AST will generate different SQL strings for MySQL and Oracle)
Also, in advanced use-cases where you're using stored procedures, jOOQ will generate objects for each procedure such that you can pretend those procedures are regular Java code, which is extremely easy to call.
Do people still need another way to make Java talk to a DB?
Yes, absolutely. jOOQ is gaining market share. None of the other vendors, nor Java EE have something like jOOQ (although JPA has Criteria API for JPQL, which is similar, but not for SQL). According to independent studies by
ZeroTurnaround or
InfoQ, the market share may already reach 5%. The surveys are from 2014, so we're expecting even more market share of the jOOQ Open Source Edition by today.
For more info, we've written up our vision for jOOQ on this website:
http://www.jooq.org/doc/latest/manual/preface
Note that jOOQ is not just about our product - we also believe that we're helping Java developers better understand the SQL language as a whole, which is why we publish many useful articles on our product blog, about Java and SQL:
http://blog.jooq.org. We also offer
trainings where we help Java developers go one step beyond with their SQL knowledge, helping them learn about things like:
- Common table expressions
- Table valued functions
- Lateral join / cross apply / outer apply
- Arrays and nested collections
- Stored procedures
- Row value expressions
- Ordered-set aggregate functions
- Window functions (my favourite)
- Bulk updates
- Advanced data types and ORDBMS features
All of the above features are made accessible very easily via jOOQ, too.
Hope this helps. Let me know if you have any additional questions.
- Lukas