Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    java
  » JDBC and AS400/iSeries Connection with JTOpen
      by sde
 Page 1 of 1 
   

(Login to remove green text ads)
JTOpen is a free tool provided by IBM to communicate with the AS400. Here I will show you how to connect and query using a native JDBC connection.

In order for this to work, you need to things: 1: The Java Toolbox must be setup on the AS400. 2: You must have the JTOpen package imported into your Java Project.

It is really just like any other JDBC connection, just with a different driver. Of course you will have to modify the sql query in order for this to work with your data.

Please read the comments in the code to understand what is going on.

Code:
package com.mycompany.data; import java.sql.*; import com.ibm.as400.access.*; public class testAS400JDBC { public testAS400JDBC(){ } public static void main(String[] args){ // define login info for as400 String host = "1.2.3.4"; String user = "USERNAME"; String pwd = "PASSWORD"; try{ // make sure driver exists Class.forName("com.ibm.as400.access.AS400JDBCDriver"); }catch(Exception e){ System.out.println(e.toString()); } try{ // create a new connection from driver Connection con = DriverManager.getConnection("jdbc:as400://" + host, user, pwd); // create new statement from connection java.sql.Statement stmt = con.createStatement(); // sql String sql="SELECT FNAME,LNAME FROM LIBRARY.FILE FETCH FIRST 10 ROWS ONLY"; // execute query ResultSet rs = stmt.executeQuery(sql); // loop through results while(rs.next()){ System.out.println(rs.getString(1) + " " + rs.getString(2)); } // close connection con.close(); }catch(Exception e){ System.out.println(e.toString()); } } }





 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle