how to connect to db2 with jdbc

hello guys:

following a slice of code

try {

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

} catch (Exception e) {}

try {

con = DriverManager.getConnection("jdbc:db2://192.168.0.1/DB", "admin", "admin");

the error "no suitable driver" will be seen when running, why ?

[335 byte] By [stephen96] at [2007-9-19]
# 1

May be your URL string is not inproper format.

Check with the documentation of driver the exact format.

When u load a driver by clas.forname() it registers iteself with driver manager.

when u call getConnection, DriverManager calls each driver registered with with it passing it the url string u passed earlier;each driver responds by sayin YES?NO

i think the driver registered here did not recognize the url format

so check if url is in proper format

arulanandamj at 2007-7-7 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
use COM.ibm.db2.jdbc.net.DB2Driver> Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newIns> the error "no suitable driver" will be seen when
mchan0 at 2007-7-7 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Include the jar file containing the DB2 driver; db2java.zip in your classpath.

Import the java.sql class library.

Import java.sql.*;

Load the JDBC driver.

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

Connection con = DriverManager.getConnection("jdbc:db2:CSE6331","username","password");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("Select * from EMP");

while (rs.next()) {

String id = rs.getString( 1 );

int name = rs.getInt( 2 );

System.out.println("emp_id:" + id + " name " + name);

}

dvohra09 at 2007-7-7 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...