Blog Archive

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 mydb2.properties

#I-series ip or host name
local_system=XXX.XXX.XXX.XXX

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

#I-series Password
password=XXXXXXX

Sample java program for JDBC connection

static Properties props;

try {

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

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

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

 conn.close();

}
catch (Exception e) {
 System.out.println(e);
}

You need the jt400.jar in your classpath for the project. You can extract a copy from the iSeries IFS directory.
/QIBM/ProdData/HTTP/Public/jt400/lib/jt400.jar


8 comments :

  1. Hi there colleagues, its fantastic article regarding educationand completely defined,
    keep it up all the time.

    ReplyDelete
  2. Hey there are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get started and set up
    my own. Do you need any coding expertise to make your own blog?
    Any help would be greatly appreciated!

    ReplyDelete
  3. Your style is really unique in comparison to other folks I have read stuff
    from. Thanks for posting when you’ve got the opportunity, Guess I’ll just bookmark
    this blog.

    ReplyDelete
  4. Hello! This post could not be written any better!

    Reading through this post reminds me of my good old room mate!
    He always kept chatting about this. I will forward this article to him.
    Pretty sure he will have a good read. Many thanks for
    sharing!

    ReplyDelete
  5. Great weblog right here! Additionally your web site rather a lot up fast!
    What web host are you the use of? Can I get your affiliate hyperlink for your host?
    I wish my site loaded up as quickly as yours lol

    ReplyDelete
  6. I visited various websites but the audio quality for audio songs current
    at this site is genuinely marvelous.

    ReplyDelete
  7. it I don't understand, why are all seven things on one single page? As a reader of The Internet I am only capable of comprehending one list item at a time! Jual Boneka Wisuda | Jaket Bomber Pria

    ReplyDelete