Eventually /dev/null

Random thoughts from an emerging Programmer

DB2 Remote Connection

As I found out within the last days it isn’t that easy to find informations about how to connect Java through JDBC with a DB2 Database remotely. So if you should come into these troubles as well, take care of this:
As DB2 driver you need to use COM.ibm.db2.jdbc.net.DB2Driver which is located in the same file (db2java.zip) as the default driver (COM.ibm.db2.jdbc.app.DB2Driver) which is “promoted” on most sites. The problem with these two drivers is that they’re not able to work with the other kind of connection. So If you inserted the net driver you can’t create local connections and vice versa. If you want to be flexible you need to use as driver com.ibm.db2.jcc.DB2Driver which is capable to handle both types of connections. The driver can be found within the db2jcc.jar file, which should be located in the same place as db2java.zip. At least for me it was further needed to provide a license in order to establish a remote connection, to achieve this add a file called db2jcc_license_cu.jar or maybe some file which is similiar named to your Classpath.
Connection string: After some search I found the DB2 page where the remote connection string was described. The string has follow this scheme for remote connections: jdbc:db2://SERVERNAME:PORT/DATABASE.
Not sure if you can leave the DATABASE and run later a Connect to DATABASE Query. At least my quick tries resulted each time with an Exception caused by wrong connection strings.
If you don’t know on which port your DB2 Instance is running take a look at your /etc/services and look for the corresponding line.
Now you should be ready to successfully open a remote Connection.