Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DTP » Can't get JDBC connection to DB2(JDBC error connecting to DB2 V9.5.2 in Eclipse)
Can't get JDBC connection to DB2 [message #512365] Thu, 04 February 2010 19:00 Go to next message
Reinhardt Christiansen is currently offline Reinhardt ChristiansenFriend
Messages: 24
Registered: July 2009
Junior Member
I'm having some trouble getting a JDBC connection to my DB2 database from within Eclipse.

I am using:
- Eclipse Galileo 3.5.1
- DB2 9.5.2
- JDBC 3.0
- type 4 driver (com.ibm.db2.jcc.DB2Driver)
- Windows XP

Files db2jcc.jar, sqlj.zip, and db2jcc_license_cu.jar are listed under Referenced Libraries in the project.

This is my code:
try {
this.connection = DriverManager.getConnection(this.url, this.login, this.password);
}
catch (SQLException sql_excp) {
String msg = "Encountered SQLException on connect to url " + this.url + "."; //$NON-NLS-1$ //$NON-NLS-2$
this.logger.logp(Level.SEVERE, this.CLASS_NAME, METHOD_NAME, msg, sql_excp);
System.exit(16);
}

The database, Resume, exists in DB2 and I can query it with the DB2 Command Editor. The following two lines exist in my services file in Windows:
db2j_DB2 55000/tcp
db2c_DB2 50000/tcp


The error is:
4-Feb-2010 9:54:36 AM com.foo.resume2010.References connectToDatabase()
SEVERE: Encountered SQLException on connect to url jdbc:db2://server:50000/Resume.
com.ibm.db2.jcc.a.en: [3.52.95] Exception [Ljava.lang.Object;@145e044: Error opening socket to server {1} on port {2} with message: {3}. ERRORCODE=-4499, SQLSTATE=08001
at com.ibm.db2.jcc.a.ad.a(ad.java:319)
at com.ibm.db2.jcc.a.ad.a(ad.java:337)
at com.ibm.db2.jcc.t4.xb.a(xb.java:375)
at com.ibm.db2.jcc.t4.xb.<init>(xb.java:76)
at com.ibm.db2.jcc.t4.a.x(a.java:263)
at com.ibm.db2.jcc.t4.b.a(b.java:1809)
at com.ibm.db2.jcc.a.ib.a(ib.java:503)
at com.ibm.db2.jcc.a.ib.<init>(ib.java:459)
at com.ibm.db2.jcc.t4.b.<init>(b.java:330)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.foo.resume2010.References.connectToDatabase(References.j ava:336)
at com.foo.resume2010.References.<init>(References.java:206)
at com.foo.resume2010.ResumeSupportFileWriterReferencesPdf.writ eFile(ResumeSupportFileWriterReferencesPdf.java:162)
at com.foo.resume2010.ResumeFileGenerator.<init>(ResumeFileGenerator.java:116)
at com.foo.resume2010.ResumeFileGenerator.main(ResumeFileGenera tor.java:72)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.ja va:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at com.ibm.db2.jcc.t4.y.run(y.java:34)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.db2.jcc.t4.xb.a(xb.java:369)
... 14 more

This is my first time setting up DB2/JDBC/Eclipse on a computer in several years. This version of DB2 has some apparent changes to DB2 Version 8, which is what I was using previously. I've gone through the DB2 manuals but can't find my mistake there.

Can anyone see what I've done wrong?

--
Rhino
Re: Can't get JDBC connection to DB2 [message #512670 is a reply to message #512365] Fri, 05 February 2010 23:40 Go to previous messageGo to next message
Brian Payton is currently offline Brian PaytonFriend
Messages: 154
Registered: July 2009
Senior Member
I created a small test program based on your code snippet, and I was
able to connect to a DB2 v9.5 server without any problem. Of course I
had to add the following code ahead of the try/catch block containing
the getConnection:

try {
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
}
catch(Exception e) {
System.out.println(e);
}

The error message indicates a problem connecting to "server" at port
50000, so please check your connection URL.

Reinhardt Christiansen wrote:
> I'm having some trouble getting a JDBC connection to my DB2 database
> from within Eclipse.
>
> I am using:
> - Eclipse Galileo 3.5.1
> - DB2 9.5.2
> - JDBC 3.0
> - type 4 driver (com.ibm.db2.jcc.DB2Driver)
> - Windows XP
>
> Files db2jcc.jar, sqlj.zip, and db2jcc_license_cu.jar are listed under
> Referenced Libraries in the project.
>
> This is my code:
> try {
> this.connection = DriverManager.getConnection(this.url, this.login,
> this.password);
> }
> catch (SQLException sql_excp) {
> String msg = "Encountered SQLException on connect to url " + this.url +
> "."; //$NON-NLS-1$ //$NON-NLS-2$
> this.logger.logp(Level.SEVERE, this.CLASS_NAME, METHOD_NAME, msg,
> sql_excp);
> System.exit(16);
> }
>
> The database, Resume, exists in DB2 and I can query it with the DB2
> Command Editor. The following two lines exist in my services file in
> Windows:
> db2j_DB2 55000/tcp
> db2c_DB2 50000/tcp
>
>
> The error is:
> 4-Feb-2010 9:54:36 AM com.foo.resume2010.References connectToDatabase()
> SEVERE: Encountered SQLException on connect to url
> jdbc:db2://server:50000/Resume
> com.ibm.db2.jcc.a.en: [3.52.95] Exception [Ljava.lang.Object;@145e044:
> Error opening socket to server {1} on port {2} with message: {3}.
> ERRORCODE=-4499, SQLSTATE=08001
> at com.ibm.db2.jcc.a.ad.a(ad.java:319)
> at com.ibm.db2.jcc.a.ad.a(ad.java:337)
> at com.ibm.db2.jcc.t4.xb.a(xb.java:375)
> at com.ibm.db2.jcc.t4.xb.<init>(xb.java:76)
> at com.ibm.db2.jcc.t4.a.x(a.java:263)
> at com.ibm.db2.jcc.t4.b.a(b.java:1809)
> at com.ibm.db2.jcc.a.ib.a(ib.java:503)
> at com.ibm.db2.jcc.a.ib.<init>(ib.java:459)
> at com.ibm.db2.jcc.t4.b.<init>(b.java:330)
> at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:197)
> at java.sql.DriverManager.getConnection(DriverManager.java:582)
> at java.sql.DriverManager.getConnection(DriverManager.java:185)
> at com.foo.resume2010.References.connectToDatabase(References.j ava:336)
> at com.foo.resume2010.References.<init>(References.java:206)
> at com.foo.resume2010.ResumeSupportFileWriterReferencesPdf.writ
> eFile(ResumeSupportFileWriterReferencesPdf.java:162)
> at
> com.foo.resume2010.ResumeFileGenerator.<init>(ResumeFileGenerator.java:116)
> at com.foo.resume2010.ResumeFileGenerator.main(ResumeFileGenera
> tor.java:72)
> Caused by: java.net.ConnectException: Connection timed out: connect
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.ja va:195)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
> at java.net.Socket.connect(Socket.java:525)
> at com.ibm.db2.jcc.t4.y.run(y.java:34)
> at java.security.AccessController.doPrivileged(Native Method)
> at com.ibm.db2.jcc.t4.xb.a(xb.java:369)
> .. 14 more
>
> This is my first time setting up DB2/JDBC/Eclipse on a computer in
> several years. This version of DB2 has some apparent changes to DB2
> Version 8, which is what I was using previously. I've gone through the
> DB2 manuals but can't find my mistake there.
>
> Can anyone see what I've done wrong?
>
> --
> Rhino
Re: Can't get JDBC connection to DB2 [message #512687 is a reply to message #512670] Sat, 06 February 2010 05:00 Go to previous messageGo to next message
Reinhardt Christiansen is currently offline Reinhardt ChristiansenFriend
Messages: 24
Registered: July 2009
Junior Member
You were absolutely right: it was the URL.

I was using:
db2:jdbc://server:50000/Resume

I thought, from the example I'd seen, that I had to use the literal 'server' but what I actually needed was a specific server name. Since my database is on the same computer as my Eclipse environment, I changed the URL to:

db2:jdbc://localhost:50000/Resume

Now everything works fine! Thanks VERY much for clearing that up!

--
Rhino
Re: Can't get JDBC connection to DB2 [message #597228 is a reply to message #512670] Sat, 06 February 2010 05:00 Go to previous message
Reinhardt Christiansen is currently offline Reinhardt ChristiansenFriend
Messages: 24
Registered: July 2009
Junior Member
You were absolutely right: it was the URL.

I was using:
db2:jdbc://server:50000/Resume

I thought, from the example I'd seen, that I had to use the literal 'server' but what I actually needed was a specific server name. Since my database is on the same computer as my Eclipse environment, I changed the URL to:

db2:jdbc://localhost:50000/Resume

Now everything works fine! Thanks VERY much for clearing that up!

--
Rhino
Previous Topic:Can't get JDBC connection to DB2
Next Topic:getting raw oracle sql explain plan?
Goto Forum:
  


Current Time: Thu Apr 25 00:17:42 GMT 2024

Powered by FUDForum. Page generated in 0.04038 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top