First. CGI has nothing to do with database access. CGI- common gateway interface is roughly equivalent to Java
Servlet API not JDBC.
You can use CGI to access database (by writing a perl script that used db access routines).CGI
I have not yet seen a reason to write a Java CGI application.
You might find some CGI classes on the net but I think you'd be better off writing JSP/Servlet with JDBC solution or a Perl/C/C++ CGI solution. I would not mix java and CGI.
Could you please elaborate on why would you want to write CGI in Java