Garrett Stevenson
Garrett Stevenson

Reputation: 156

Connecting to Remote DB2 Database (JSP)

Let me preface this by saying I am completely new at this kind of thing. Anyways..

I am trying to connect to a DB2 Database. The server is running Ubuntu 12.04 and Apache Tomcat 7. The driver db2jcc.jar is included in the build path.

Here is my JSP code:

<%@ page import="java.sql.*" %>
<% Class.forName("com.ibm.db2.jcc.DB2Driver");%>
<HTML>
<HEAD>
<TITLE>db2 connection</TITLE>
</HEAD>
<BODY>
<%
  String url = 
  "jdbc:db2://IP_ADDR:60000/INST1" +
  ":user=USERNAME;password=PASSWORD;" +
  "traceLevel=" +
  (com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL) + ";";
  Connection con = java.sql.DriverManager.getConnection(url);
%>
</BODY>
</HTML>

The error message I am getting:

The application server rejected establishment of the connection. An attempt was made to access a database, INST1, which was either not found or does not support transactions. ERRORCODE=-4499, SQLSTATE=08004

I checked out the IBM Support page on the issue here: http://www-01.ibm.com/support/docview.wss?uid=swg21443723

It mentions using the target directory name, found by issuing the db2 list dcs directory command.

On the server, mine was initially blank, but I created an entry using the db2 catalog dcs database DB2INST1 as INST1 command.

Now my output for using db2 list dcs directory` is as follows:

Database Connection Services (DCS) Directory

Number of entries in the directory = 1

DCS 1 entry:

Local database name = DB2INST1

Target database name = INST1

Application requestor name =

DCS parameters =

Comment =

DCS directory release level = 0x0100

I reset the database by doing db2stop and db2start

Finally, I ran netstat -tulpn and saw the database was listening on port 60000. Output below:

tcp 0 0 0.0.0.0:60000 0.0.0.0:* LISTEN

2949/db2sysc

This is as far as I got. From what I can tell I am using the target database name and trying to connect to the correct port number.

Am I barking up the right tree here? Any help is greatly appreciated.

** Edit: Formatted answer to mustaccio's response **

On the server, I go down a level after I ssh on. I get 4 directories named <USERNAME>, dasusr1, db2fenc1, db2inst1

From there I did sudo su db2inst1 then ran the db2 list dcs directory command to get:

Database Connection Services (DCS) Directory
Number of entries in the directory = 1

DCS 1 entry:

Local database name                = DB2INST1
Target database name               = INST1
Application requestor name         =
DCS parameters                     =
Comment                            =
DCS directory release level        = 0x0100

Upvotes: 2

Views: 10064

Answers (1)

renaissanceMan
renaissanceMan

Reputation: 433

It's been a while but for other people looking for a solution to this db2 connectivity problem. If people want to test physical connectivity of their development machine to the db2 server use CLPPlus that comes with the DB2 driver and manually put in the connection parameters to make sure you have physical connectivity. My environment is quite different than Garret's above but I want to offer one more clue that might help people connect. I was using VS 2015 enterprise with SSIS. I used CLPPlus to confirm physical connectivity then started trying to connect and ADO.Net source to db2. I had to override the port for my server credential db2server.mydomain.com:523 to override the port to 523. Then something funny happened. SSIS was fussing about the connection and I started looking at the parameters. One of the parameters was Authentication, which you could probably code in jdbc. I put in DB2 (as opposed to ldap or some other wallet) as the value for Authentication and it worked.

Upvotes: 0

Related Questions