The Artima Developer Community
Sponsored Link

Java Answers Forum
Connect to DB2 with Java

2 replies on 1 page. Most recent reply: Oct 31, 2003 4:26 AM by Bart Moelans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Bart Moelans

Posts: 2
Nickname: moelitec
Registered: Oct, 2003

Connect to DB2 with Java Posted: Oct 30, 2003 6:14 AM
Reply to this message Reply
Advertisement
I'm trying to make a connection to a remote server. If I work on the server himself following code works:

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
dbname = "sample";
DriverManager.getConnection("jdbc:db2:sample_db");

Now I want to do the same from another pc, al the mauals say it shoud be something like:

Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");

dburl = "xxx.xx.xx.xxx"; //I don't tell you that :-)
dbport = "yyyyy";
dbname = "sample";

DriverManager.getConnection("jdbc:db2://"+dburl+":"+dbport+"/"+dbnam e,"user","pasword");

I don't get an error message, the program just hangs at the last statement.
There is no mistake in my dburl or dbport, cause I give a wrong url/port I get te fault "Error opening socket".
But when I give the wrong dbname, user or password, still nothing happens, and then I mean nothing, de program just hangs.


Senthilnathan

Posts: 13
Nickname: ssnathan
Registered: Jul, 2003

Re: Connect to DB2 with Java Posted: Oct 30, 2003 4:16 PM
Reply to this message Reply
If you find the jcc driver in the directory db2/jcc try,
Class.forName("COM.ibm.db2.jcc.DB2Driver").newInstance();
instead of,
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");

In DB2 8.1, this (jcc) new type 4 driver has been introduced.

Bart Moelans

Posts: 2
Nickname: moelitec
Registered: Oct, 2003

Re: Connect to DB2 with Java Posted: Oct 31, 2003 4:26 AM
Reply to this message Reply
Now the 'DriverManager.getConnection' statement works, but now the following statements don't work, although with the 'COM.ibm.db2.jdbc.net.DB2Driver'-driver, they work fine.

System.out.println("SQL-step 1");
Statement stmt = con.createStatement();
System.out.println("SQL-step 2");
String qstring = "select * from sample";
System.out.println("SQL-step 3");
ResultSet rs = stmt.executeQuery(qstring);

Everything goes fine untill the 'stmt.executeQuery' statement, then I get an errror.

Flat View: This topic has 2 replies on 1 page
Topic: Exporting data from a servlet to a dynamically specified Excel file Previous Topic   Next Topic Topic: Replacement for getServletNames() / getServlets()

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use