Can't get JDBC connection to DB2 [message #597177] |
Thu, 04 February 2010 19:00 |
Reinhardt Christiansen 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 #597211 is a reply to message #597177] |
Fri, 05 February 2010 23:40 |
Brian Payton 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
|
|
|
Powered by
FUDForum. Page generated in 0.02390 seconds