Re: JDBC connection Issues
Thank you for your help.
I wanted to follow up with my solution in case someone else stumbles
on this thread.
I used JTOpen from http://jt400.sourceforge.net/
With it everything is straight forward no license files, no DB connect
to deal with...
If anyone stumbles on this thread simply make sure jt400.jar is in the
class path available from the link provided.
and use the following code as a guide:
import java.sql.*;
public class Main
{
public static void main(String[] args){
// define login info for as400666
String host = "192.168.1.111/DBName";
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";
String sql="SELECT * FROM CO02DT.DTNAME 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) + " " +
rs.getString(3)) ;
}
//System.out.println(rs);
// close connection
con.close();
}catch(Exception e){
System.out.println(e.toString());
}
}
}