Java JDBC connection to DB2 AS400 database example

To make a connection to DB2 on AS400 using JDBC we need the following values

  • Host Name or IP Address of The Machine
  • User Id
  • Password

Instead of putting the values right into the program its better to soft code them using a properties file.

Sample properties file for JDBC connection

#I-series ip or host name

#I-series UserId, used for login and library list

#I-series Password

Sample java program for JDBC connection

static Properties props;

try {

 props = new Properties();
 props.load(new FileInputStream("properties/"));

 String DRIVER = ""; 
 String URL = "jdbc:as400://" + props.getProperty("local_system").trim() + ";naming=system;errors=full";
 Connection conn = null;

 //Connect to iSeries 
 conn = DriverManager.getConnection(URL, props.getProperty("userId").trim(), props.getProperty("password").trim()); 


catch (Exception e) {

You need the jt400.jar in your classpath for the project. You can extract a copy from the iSeries IFS directory.

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.