Discussion:
Can´t connect java based app
(too old to reply)
d***@uniandes.edu.co
2007-10-04 20:03:03 UTC
Permalink
I´m trying to connect a java based program with DB2 but have been unable to do so. DB2 is installed on a virtual machine.

The facts:

- Java program is on Eclipse
- Eclipse is on my host computer which is a windows xp machine
- DB2 is installed on a Linux (Red Hat) Virtual Machine inside my windows xp machine
- Virtual Machine has IP address 192.168.152.128
- I have a DB created in the virtual machine, the DB´s name is PHONEDB
- The instance owner is inst00 and the password is passw0rd
- I´ve installed the runtime client on my windows machine with the same version and same fix pack as the DB2 thats installed in my virtual machine
- I´ve configured the environment variables correctly on my windows machine
- I added the corresponding jdbc type 2 (db2java.jar) in the windows environment variables and in eclipse as a library in the java build path
- I´m able to ping the Virtual Machine, connect to it and catalog the PHONEDB data base
- I can access the DB from my windows machine through CLP. I can run queries against it with no problems.


What I´m unable to do is make my java program connect to the DB.

Code:

// load the DB2 Driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver"); //This works
// establish a connection to DB2
String url = jdbc:db2://192.168.152.128:50000/PHONEDB:user=inst00;password=passw0rd";
Connection conexion = DriverManager.getConnection(url);

The error I keep getting is this one:
java.sql.SQLException: No suitable driver found for jdbc:db2://192.168.152.128:50000/PHONEDB:user=inst00;password=passw0rd
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at conexion.Connect.main(Connect.java:19)


What I think I have to do but haven´t been able:
- Try using port 6789 with DB2 but I don´t know how to enable this port for listening
- Writing the string in some other strange way that I haven´t been able to do so

Thanks in advance
Knut Stolze
2007-10-05 09:50:53 UTC
Permalink
Post by d***@uniandes.edu.co
I´m trying to connect a java based program with DB2 but have been unable
to do so. DB2 is installed on a virtual machine.
- Java program is on Eclipse
- Eclipse is on my host computer which is a windows xp machine
- DB2 is installed on a Linux (Red Hat) Virtual Machine inside my windows
xp machine - Virtual Machine has IP address 192.168.152.128
- I have a DB created in the virtual machine, the DB´s name is PHONEDB
- The instance owner is inst00 and the password is passw0rd
- I´ve installed the runtime client on my windows machine with the same
version and same fix pack as the DB2 thats installed in my virtual machine
- I´ve configured the environment variables correctly on my windows
machine - I added the corresponding jdbc type 2 (db2java.jar) in the
windows environment variables and in eclipse as a library in the java
build path - I´m able to ping the Virtual Machine, connect to it and
catalog the PHONEDB data base - I can access the DB from my windows
machine through CLP. I can run queries against it with no problems.
What I´m unable to do is make my java program connect to the DB.
// load the DB2 Driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver"); //This works
// establish a connection to DB2
String url =
jdbc:db2://192.168.152.128:50000/PHONEDB:user=inst00;password=passw0rd";
Post by d***@uniandes.edu.co
Connection conexion = DriverManager.getConnection(url);
Have you tried to remove the userid/password from the connection string and
provide that information as separate parameters to the "getConnection"
method?
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Ian
2007-10-08 17:42:56 UTC
Permalink
Post by d***@uniandes.edu.co
I´m trying to connect a java based program with DB2 but have been unable to do so. DB2 is installed on a virtual machine.
- Java program is on Eclipse
- Eclipse is on my host computer which is a windows xp machine
- DB2 is installed on a Linux (Red Hat) Virtual Machine inside my windows xp machine
- Virtual Machine has IP address 192.168.152.128
- I have a DB created in the virtual machine, the DB´s name is PHONEDB
- The instance owner is inst00 and the password is passw0rd
- I´ve installed the runtime client on my windows machine with the same version and same fix pack as the DB2 thats installed in my virtual machine
- I´ve configured the environment variables correctly on my windows machine
- I added the corresponding jdbc type 2 (db2java.jar) in the windows environment variables and in eclipse as a library in the java build path
- I´m able to ping the Virtual Machine, connect to it and catalog the PHONEDB data base
- I can access the DB from my windows machine through CLP. I can run queries against it with no problems.
What I´m unable to do is make my java program connect to the DB.
// load the DB2 Driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver"); //This works
// establish a connection to DB2
String url = jdbc:db2://192.168.152.128:50000/PHONEDB:user=inst00;password=passw0rd";
Connection conexion = DriverManager.getConnection(url);
This JDBC URL is for a type 4 driver. You're specifying the type 2
driver.

If you want to use the Type 2 driver, you first need to define the
connection to the database from the DB2 tools on your Windows XP
machine. i.e., use the Client Configuration Assistant to define
the connection to the PHONEDB database. Then, use the JDBC URL:

jdbc:db2:PHONEDB


Alternatively, use the Type 4 driver:

com.ibm.db2.jcc.DB2Driver

Loading...