Ask the Expert

Using DB2 Connect and Java to connect to AS/400

Do you have any specific coding examples of using DB2 Connect and Java to connect to an AS/400. I was using the AS/400 Toolbox (that worked OK), but need to switch to DB2 Connect (our standard). I keep getting this message:

"jdbc:db2://VGIBKP1|stacktrace=|stack=java.sql.SQLException: No suitable driver; at java.sql.DriverManager.getConnection(DriverManager.java:477)". I'm not really sure my local host format is correct. Can you put in a URL? Or, is it the machine name or RDB name?


I've only used DB2 Connect with S390 and Smalltalk. I think it IS a good product that was very useful when we wanted flexibility in where to send our data....

I'm sorry I don't have a DB2 Connect example for you for JDBC specifically. Given that DB2 Connect IS defining a local name for the remote database, I assume it would use the same naming convention as the local DB2 protocol:

jdbc:db2:

IF that is NOT the correct protocol, try:

jdbc:db2://

This is the format you appear to already have tried.

On the JDBC side, you CAN specify WHICH driver to load rather than let the DriverManager try to make the decision based on the URL and the registered drivers he has access to (that's the preferred model for locating the right driver for a URL format )....

Here's the normal way to access a driver ..

java.sql.Driver aDriver =
java.sql.DriverManager.getDriver(aUrl);
java.sql.Connection aDbConnection =
aDriver.connect(aUrl, properties);

Here's a direct access of the DB2 UDB driver ...

java.sql.Driver aDriver = (java.sql.Driver)
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
java.sql.Connection aDbConnection =
aDriver.connect(aUrl, properties);

Also, the AS/400 Java Toolkit supports JDBC 2.0, is a type 4 driver and, therefore, supports J2SE, J2EE. My understanding of DB2 Connect is that it currently is back at JDK 1.1.8. Check the IBM DB2 site to see if they have any new updates on DB2 Connect. I definitely do all our development on Java 2, especially any server Java for Web applications...

Sorry I didn't have a specific DB2 Connect example...

Jim Mason


This was first published in April 2001

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: