|
If you're using the AS/400 Toolbox for Java jar or zip file (jt400.zip for
example) when building your app, you can use a section of code like the
following to connect via a JDBC driver:
try {
// Register AS/400 JDBC Driver:
DriverManager.registerDriver (new AS400JDBCDriver ());
// Connect to AS/400:
Connection c = DriverManager.getConnection(
"jdbc:as400://myas400;naming=sql;errors=full",
"myuser",
"mypwd");
// Run a query to load a result set:
// First create an SQL statement:
Statement s = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
// Then execute a statement:
ResultSet rs = s.executeQuery (
"SELECT STDNAM FROM BCSSTUDENT.PAOSSTU WHERE STDCLS = '11' ORDER BY
STDNAM");
// Then loop through ResultSet records to load combo box:
// For now, just load first student so we don't have to wait.
rs.first();
jComboBox1.addItem(rs.getString("STDNAM"));
// Close the statement and disconnect:
s.close();
c.close();
} // try
catch (SQLException sqle) {
sqle.printStackTrace();
} // catch
In this case BCSSTUDENT is the name of an AS/400 library (also known as a
database or collection), and PAOSSTU is the name of the file (AKA table).
For less coding, I used an import statements like the following at the top
of the program:
import java.sql.*;
import com.ibm.as400.access.*;
You can also refer to the Toolkit programmer's guide for good examples and
explanations:
http://publib.boulder.ibm.com/pubs/html/as400/v4r5/ic2924/info/java/rzahh/to
olbox.htm
Once there, look under the Access classes for the section on JDBC.
Hope that helps.
-----Original Message-----
From: Bartell, Aaron L. (TC) <ALBartell@taylorcorp.com>
To: 'JAVA400-L@midrange.com' <JAVA400-L@midrange.com>
Date: Friday, March 09, 2001 11:40 AM
Subject: Generic JDBC driver.
>Hi all,
>
>I have written my first java pgm's on the 400 that were rather simple, and
>now I want to get into more complex coding with file I/O and stuff.
>
>I can't seem to find an SQL driver so I can access my AS/400's DB. I have
>tried AS400JDBCDriver.class but it does not exist. I have looked in
>\\My400\QIBM\ProdData\Java400\com\ibm\as400\access in the IFS but cannot
>find anything that would resemble a file I/O driver.
>
>Where should I look next? Can I just copy one from another 400 or does it
>need to be installed or something? Help . . .
>
>Aaron Bartell
>+---
>| This is the JAVA/400 Mailing List!
>| To submit a new message, send your mail to JAVA400-L@midrange.com.
>| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
>| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
>| Questions should be directed to the list owner: joe@zappie.net
>+---
>
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.