If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Not able to connect to db2 from java

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-26-11, 16:51
girishmb79 girishmb79 is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
Not able to connect to db2 from java

Hi All,

I am not able to connect to DB2 database from java, no matter what driver I use. I am using (db2java.zip and db2jcc.jar) or (db2jcc_license_cu.jar and db2jcc.jar and db2jcc_license_cisuz.jar)

I either get
"No suitable driver found" for For Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

OR

Class.forName("com.ibm.db2.jcc.DB2Driver");

"Exception in thread "main" com.ibm.db2.jcc.am.yn: [jcc][t4][2030][11211][3.57.82] A communication error occurred during operations on the connection's underlying socket, socket input stream,
or socket output stream. Error location: Reply.fill(). Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001"

Thank you for your help in Advance.
Reply With Quote
  #2 (permalink)  
Old 10-26-11, 18:05
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
Not sure if this helps -- but we recently set up java for 8.2 64-bit, here are the steps that I wrote down from then.. maybe you can double check if this applies to your server, good luck!


1. yum install libXp-1.0.0-8.1.el5.i386
rpm -ivh IBMJava2-AMD64-142-SDK-1.4.2-13.9.x86_64.rpm
rmp -ivh IBMJava2-AMD64-142-JRE-1.4.2-13.9.x86_64.rpm

2. Make sure JDK_PATH is set to /opt/IBMJava2-amd64-142
db2 get dbm cfg | grep JDK_PATH

If not, then set it with the update dbm command --

db2 update dbm cfg USING JDK_PATH /opt/IBMJava2-amd64-142
db2stop
db2start

3. Go to /etc/profile and add the following lines above the line that says
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

export PATH=$PATH:/opt/IBMJava2-amd64-142/jre/bin
export JAVA_HOME=/opt/IBMJava2-amd64-142
export CLASSPATH=.:$JAVA_HOME/lib/classes.zip:/$JAVA_HOME/lib


4. Add a path to the shared libraries in /etc/ld.so.conf

vi /etc/ld.so.conf
Add the following line-- /opt/IBMJava2-amd64-142/jre/bin

Give the command ldconfig for changes to take effect
exit out / log back in to test
Reply With Quote
  #3 (permalink)  
Old 10-27-11, 09:26
girishmb79 girishmb79 is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
Thanks for the reply.


I am trying to connect from Eclipse.
Reply With Quote
  #4 (permalink)  
Old 10-27-11, 10:31
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What is the exact java statement that is failing and what is the exact error you are getting?

Andy
Reply With Quote
  #5 (permalink)  
Old 10-27-11, 10:39
girishmb79 girishmb79 is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
I am using db2jcc.jar and db2jcc_license_cu.jar in RAD/Eclipse
Java version - 1.5


Class.forName("com.ibm.db2.jcc.DB2Driver");
String url ="jdbc:db2://<HostName>:1209/<DB Name>";

Connection con = DriverManager.getConnection(url,"UID","PW");

I am getting error in the last line (Connetion con)

com.ibm.db2.jcc.am.yn: [jcc][t4][2030][11211][3.57.82] A communication error occurred during operations on the connection's underlying socket, socket input stream,
or socket output stream. Error location: Reply.fill(). Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001
Reply With Quote
  #6 (permalink)  
Old 10-27-11, 10:53
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
On the server <HostName>, what port is the DB2 instance running on?

Andy
Reply With Quote
  #7 (permalink)  
Old 10-27-11, 11:13
girishmb79 girishmb79 is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
Andy,

Its running on port 1209
Reply With Quote
  #8 (permalink)  
Old 10-27-11, 11:17
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by girishmb79 View Post
ERRORCODE=-4499, SQLSTATE=08001
Quote:
Originally Posted by the fine manual
-4499 text-from-getMessage

Explanation: A fatal error occurred that resulted in a disconnect from the data source. The existing connection has become unusable.

User response: Call SQLException.getMessage to retrieve specific information about the problem.
............................
Reply With Quote
  #9 (permalink)  
Old 10-27-11, 11:20
girishmb79 girishmb79 is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
I did that and I got the same error infor

Message()..[jcc][t4][2030][11211][3.57.82] A communication error occurred during operations on the connection's underlying socket, socket input stream,
or socket output stream. Error location: Reply.fill(). Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001
Reply With Quote
  #10 (permalink)  
Old 10-27-11, 11:21
girishmb79 girishmb79 is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
Is there a way for me to connect to DB2 database using DSN entry ? or ODBC connection

Last edited by girishmb79; 10-27-11 at 11:25.
Reply With Quote
  #11 (permalink)  
Old 10-27-11, 11:45
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Using DSN entry should work. Port 1209 is very unusual for DB2. What OS is the server and what DB2 version?

Andy
Reply With Quote
  #12 (permalink)  
Old 10-27-11, 12:08
girishmb79 girishmb79 is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
DB2 is on Mainframe. Not sure about the db2 vesion, I guess its the laterst version.

Can you help me how to connect using DSN in JAVA?
Reply With Quote
  #13 (permalink)  
Old 10-27-11, 12:50
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by girishmb79 View Post
I am using db2jcc.jar and db2jcc_license_cu.jar in RAD/Eclipse
Quote:
Originally Posted by girishmb79 View Post
DB2 is on Mainframe
You'll need db2jcc_license_cisuz.jar to connect to System z.

Must Read before posting
Reply With Quote
  #14 (permalink)  
Old 10-27-11, 13:34
girishmb79 girishmb79 is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
Sorry, I am new to this.

I do have db2jcc_license_cisuz.jar included in the class path.

If I can't succeed in connecting to DB2 by above method, can some onehelp me how to connect using DSN in JAVA?

Any pointers would be appreciated.
Reply With Quote
  #15 (permalink)  
Old 10-27-11, 14:10
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You'll need to:
- install DB2 client
- install DB2 connect
- catalog the database (CATALOG DATABASE and CATALOG DCS database commands)
- catalog the datasource (CATALOG ODBC DATA SOURCE)
- use the Type 2 ("app") driver (COM.ibm.db2.jdbc.app.DB2Driver) to connect

Should be enough keywords for you to research further.
Reply With Quote
Reply

Tags
db2, db2java, java, jcc

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On