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
    forums
Go Back   Code Forums > Code Newbie > Submit Tutorials > Java
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 05-17-2004, 09:42 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
JDBC and AS400/iSeries Connection with JTOpen

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()); } } }
__________________
testing 1 2 3
sde is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 09:00 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





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