PostgreSQL JDBC with GCJ
Friday, November 11, 2011 1:28:55 PM
As of GCC 4.1 (used in this example) it does not compile the JDBC 4 driver, so JDBC 3 was used.
Step 1: Download the JDBC 3 driver from the PostgreSQL JDBC website.
Step 2: Compile the jar file:
gcj -c postgresql-9.1-901.jdbc3.jar
Step 3: In the application, load the driver with
Class.forName( "org.postgresql.Driver" );Note that this is not needed when using the JDBC 4 driver with Oracle Java or OpenJDK.
Step 4: Compile the application
gcj -c Hello.java
Step 5: Link the object files with postgresql-9.1-901.jdbc3.o:
gcj -o hello --main=Hello Hello.o postgresql-9.1-901.jdbc3.o
The example application does nothing but print out the connection object to demonstrate it was able to connect to the database. If it does not connect an exception is thrown which prints a stack trace instead.