Apache Sqoop Codegen works by taking a table schema structure as an input and generate a JAVA DAO class and using the Sqoop import process we can initiate the Java record definition as well. In case there is a failure in the Java source then that can also be created again.

Codegen Syntax

The following is the syntax for Apache Sqoop Codegen.

sqoop codegen (generic-argument) (codegen-argument)

Codegen Example

We will see an example to generate Java code for the “employee” table that is present in the “userdata” database of MySQL.

Command:

cloudduggu@ubuntu:~$ sqoop codegen --connect jdbc:mysql://localhost/userdata?serverTimezone=UTC --username root --password cloudduggu --table employee

Output:

sqoop codegen example

For output we can see java classes are jar files are created under “/tmp/sqoop-cloudduggu/compile/ac32243542f60d7918cc2bba075bbc2d” directory.

Let us verify it.

Command:

cloudduggu@ubuntu:~$ cd /tmp/sqoop-cloudduggu/compile/ac32243542f60d7918cc2bba075bbc2d
cloudduggu@ubuntu:/tmp/sqoop-cloudduggu/compile/ac32243542f60d7918cc2bba075bbc2d$ ls -lrt

Output:

sqoop codegen data verify