VOOZH about

URL: https://www.javacodegeeks.com/2014/10/write-sql-in-java-with-jooq.html

⇱ Write SQL in Java with jOOQ - Java Code Geeks


jOOQ is a “database first”, type safe SQL API that allows you to write SQL in Java intuitively as if the SQL language were supported natively by the Java compiler.

All database schemas, tables, columns, procedures, and other objects are made available as Java objects that can be used directly in the jOOQ SQL API.

Let’s see how it works…

 
 
 

For instance, let’s assume your database consists of this table:

CREATE TABLE CUSTOMER (
 ID INT, 
 FIRST_NAME VARCHAR(50),
 LAST_NAME VARCHAR(50),
 AGE INT
);

When you run jOOQ’s code generator against it, then you will be able to interact with your database as follows:

dsl.select(CUSTOMER.FIRST_NAME, CUSTOMER.LAST_NAME)
 .from(CUSTOMER)
 .where(CUSTOMER.AGE.gt(20))
 .and(CUSTOMER.LAST_NAME.like("S%"))
 .fetch();

jOOQ’s main features are:

  • Database first: Your database holds your most important asset – your data. You want to be in control of your SQL.
  • Typesafe SQL: Use your IDE to write SQL efficiently in Java.
  • Code generation: Your Java compiler will detect errors early.
  • Active Records: Don’t write repetitive CRUD, just easily store modified records.

👁 jooq-banner

But jOOQ also ships with a variety of secondary features:

  • Multi-tenancy: Configure schema and table names at runtime, and implement row-level security.
  • Standardization: Write SQL that works on all your databases without wasting time on concrete syntax.
  • Query Lifecycle: Hook into the SQL code generation lifecycle, for logging, transaction handling, ID generation, SQL transformation and much more.
  • Stored Procedures: Calling them or embedding them in your SQL is a one-liner. Don’t waste time with JDBC.

Curious? Get started with the FREE JCG Academy Course on jOOQ!

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

Tags
jOOQ
👁 Photo of Ilias Tsagklis
Ilias Tsagklis
October 30th, 2014Last Updated: December 9th, 2019
0 103 1 minute read

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz