dcsimg
AS/400 access through JDBC/JTOPEN
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jane_Addoum
Posted On:   Wednesday, January 7, 2004 02:30 AM

I want to write a java application that will read data from an AS/400 system , for that reason I am using JTOpen JDBC driver and SDK 1.4 I haven't had any success getting the JDBC connection to work , any help would be greatly appretiated . note that I have added the classpath info , and that i can connect to the AS/400 system using ODBC . below is the JAVA code i am using to test the connection: import java.sql.*; public class Create4JData { static String[] SQLData = { "(1, 'Beth', 'Fri', 2, 'Cappuccino')", "(2, 'jDuke', 'Fri', 1, 'Latte')" }; pub   More>>

I want to write a java application that will read data from an AS/400 system ,

for that reason I am using JTOpen JDBC driver and SDK 1.4


I haven't had any success getting the JDBC connection to work , any help would be greatly appretiated .


note that I have added the classpath info ,
and that i can connect to the AS/400 system using ODBC .

below is the JAVA code i am using to test the connection:



import java.sql.*;

public class Create4JData
{

static String[] SQLData =
{
"(1, 'Beth', 'Fri', 2, 'Cappuccino')",
"(2, 'jDuke', 'Fri', 1, 'Latte')"
};

public static void main(String[] args)
{

Connection con = null;
int iRowCount = 0;
Statement stmt = null;

String sDriver =
"com.ibm.as400.access.AS400JDBCDriver";
String sURL =
"jdbc:as400://128.10.10.50/MYDATABASE;trace=true";
String sUsername = "IBAD";
String sPassword = "IBAD";

try // Attempt to load the JDBC driver
{ // with newInstance
Class.forName( sDriver ).newInstance();
}
catch( Exception e ) // error
{
System.err.println(
"Failed to load current driver.");
return;
} // end catch

try
{

con = DriverManager.getConnection ( sURL,
sUsername,
sPassword);
stmt = con.createStatement();
}
catch ( Exception e)
{
System.err.println( "problems connecting to " +
sURL + ":" );
System.err.println( e.getMessage() );

if( con != null)
{
try { con.close(); }
catch( Exception e2 ) {System.err.println( e2.getMessage() );}
}

return;
} // end catch

// to allow the program to be run more than once,
// attempt to remove the table from the database
try
{
stmt.executeUpdate( "DROP TABLE JJJJData" );
System.out.println(
"Table JJJJData was removed.");
}
catch ( Exception e ) { System.err.println( e.getMessage() );/* don't care */ }


// execute SQL commands
// to create table and insert data
try
{
stmt.executeUpdate( "CREATE TABLE JJJJData (" +
"Entry INTEGER NOT NULL, " +
"Customer VARCHAR (20) NOT NULL, " +
"DOW VARCHAR (3) NOT NULL, " +
"Cups INTEGER NOT NULL, " +
"Type VARCHAR (10) NOT NULL," +
"PRIMARY KEY( Entry )" +
")" );

System.out.println(
"Table JJJJData was created.");

for (int i = 0; i < SQLData.length; i++)
{
iRowCount +=
stmt.executeUpdate(
"INSERT INTO JJJJData VALUES " +
SQLData[i] );
}

System.out.println( iRowCount +
" Rows inserted into JJJJData.");

}
catch ( Exception e )
{
System.err.println(
"problem with SQL sent to " + sURL + ":" );
System.err.println( e.getMessage() );
}
finally
{
try { stmt.close(); }
catch( Exception e ) {System.err.println( e.getMessage() );}

try { con.close(); }
catch( Exception e ) {System.err.println( e.getMessage() );}
} // end finally clause

} // end main

} // end class Create4JData





Result :

as400: Driver AS/400 Toolbox for Java JDBC Driver (22068557) : Using IBM Toolbox for Java JDBC driver implementation.
problems connecting to jdbc:as400://128.10.10.50/MYDATABASE;trace=true:
null





I only receive "null" when i run this code !!!

PLEASE help .

   <<Less

Re: AS/400 access through JDBC/JTOPEN

Posted By:   David_Thornton  
Posted On:   Thursday, February 26, 2004 10:56 PM

Is the database host server started on the AS/400?


STRHOSTSVR SERVER(*DATABSE)


This would be my first guess as you don't appear to be getting a connection at all.

About | Sitemap | Contact