Connect to DB2

Posted on 2002-05-23
Last Modified: 2008-03-06
In my Linux platform, I need to connect to a DB2 database under OS400 with JSP, could you give me a solution?
Question by:Yuanyu
  • 4
  • 2
  • 2
  • +2

Accepted Solution

kotan earned 500 total points
ID: 7031173
There are 2 different JDBC drivers for the AS/400 database. Which one you want to use?

1. The "native" JDBC driver.
   This is shipped as part of the AS/400 Developer Kit for Java (57xxJV1). It is implemented by making native method calls to the SQL CLI (Call Level Interface). Consequently, it only runs on the AS/400 JVM.

2. The "Toolbox" JDBC driver
   This is shipped as part of the IBM Toolbox for Java (57xxJC1). It is implemented by making direct socket connections to the database host server. This happens to be the same route that the Client Access/400 ODBC driver takes. However, Client Access/400 is NOT required. The Toolbox runs on any JVM.


Expert Comment

ID: 7031178

Author Comment

ID: 7031263
Does the second way means:
57xxJC1 is in the list LICPGM, we can connect to DB2/OS400 from Linux or Windows platform without any driver installion?  
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Expert Comment

ID: 7031312
yes! The driver is already included in IBM Toolbox.
LVL 92

Expert Comment

ID: 7031406
One of IBM's red books may help you:

Author Comment

ID: 7031451
OS/400 version is V4R2, can I use toolbox 57xxJC1?

Expert Comment

ID: 7031517
LVL 19

Expert Comment

ID: 7032701
once you have your jdbc driver downloaded.. include it in your servlet container's environment as a standard lib.

you can go here to find out how to use JDBC to connect to your DB: [overview on db2 and jdbc] [tutorial about using jdbc from a jsp to connect to a DB, registration is free] [how to access db2 data using jdbc in java/jsp]

here is a redbook on it:

if you can't find the IBM Supplied JDBC driver here is an alternative one:

here is how to set up the IBM JDBC driver:

LVL 19

Expert Comment

ID: 7075697
any luck?


Expert Comment

ID: 7100256
Ok Yuanyu,

I think i am in a better positions to help cause I have just finished my project in JSP on DB2 and OS400. I think u need mor sample code other than looking around in the info center again.

First, I am using JSP and JavaBean to work. To gather info from user, I used JSP to capture user information, after that I used JavaBEan to do the connection. So, for your problems, u need to know how to connect right? Here your are :

********** ********

1 package;
3import java.sql.*;
4import java.util.*;
6public class Books {
7        String error;
8        Connection con;
10        public Books() { }
12        public void connect() throws ClassNotFoundException,
13                                     SQLException,
14                                     Exception {
15        try {
16           Class.forName("");
17           con = DriverManager.getConnection("jdbc:db2:*local");
18        } catch (ClassNotFoundException cnfe) {
19          error = ("ClassNotFoundException: Could Not Locate Db Driver");
20          throw new ClassNotFoundException(error);
21        } catch (SQLException cnfe) {
22          error = ("ClassNotFoundException : Could Not Connect to DB.");
23          throw new SQLException(error);
24        } catch (Exception e) {
25          error = ("Exception : An Unknown error occur.");
26          throw new Exception (error);
27        }
28      }
31        public void disconnect() throws SQLException {
32           try {
33                if ( con != null) {
34                     con.close();
35                   }
36                } catch (SQLException sqle) {
37                  error = ("SQLEXception : Unable to close the database.");
38                  throw new SQLException (error);
39                }
40              }
43        public ResultSet viewBooks() throws SQLException, Exception {
44                ResultSet rs = null;
46                try {
47                 String queryString =("SELECT TA1001, TA1021, TA1015 FROM lflib.jalf11 WHERE TA1014='C1'");
48                 Statement stmt = con.createStatement();
49                 rs = stmt.executeQuery(queryString);
50              } catch (SQLException sqle) {
51                        error = ("SQLException : Could not execute query");
52                        throw new SQLException (error);
53              } catch (Exception e) {
54                        error = ("Exception : An Unknown error occur.");
55                        throw new Exception (error);
56              }
58              return rs;
59       }
61       }

The bean above, as u see, quite clear right? 3 methods. One is doing the connection, which is include of all the driver, location of thedb etc... The second fucntions is disconnect, which u need to close all the connectivity to the db before u close the pages. The third one is the query part. U can put any type of SQL command here as long as it's a valid command.

Hope it's can help.

Oh yeah... regarding your 5722-JV1 or any other licienced programs. As long as it's in the INSTALLED or COMPATIBLE mode, it's can be used. And u no need to specific anythings in order for u to used. No need. U can straight away used this.


Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with LDAp login using jsp 6 113
caughtSpeeding java challenge 16 136
spring example non maven 4 87
null output 3 24
Learn how the use of a bunch of disparate tools requiring a lot of manual attention led to a series of unfortunate backup events for one company.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question