Saturday, 21 December 2013

How to generate jOOQ code using eclipse ?


jOOQ generates Java code from your database and lets you build typesafe SQL queries through its fluent API. In this example we will see how to generate code using eclipse and MySql

1. Create a Java project and add below jars in the class path

1. jooq-xxxx.jar –This is the core library for jOOQ

2. jooq-meta-xxxx.jar- This jar includes utility class to navigate database schema for code generation

3. jooq-codegen-xxxx.jar- Utility to generate code for database schema

All these jars are available in

4. Java mysql connector jar- Available in

2. Create a database schema and table in MySql database


3. Create below xml under project src folder (student.xml)

In this xml file we need to mention database connection and schema details to generate code

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="">

4. Eclipse run configuration

Right click on the project and select ‘Run As’ Run configuration and Select main class org.jooq.util.GenerationTool

image l

Argument parameter should be the xml file which we created in step 3


5. Run it

Run the org.jooq.util.GenerationTool and we can see the codes are generated in the target directory which we mentioned in the student.xml file
Final structure of the project