Hi I am trying to make DB2 connection but its throwing exception...Here is the code and output
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class
Test {
public static void main(
String args[])
{
String url="jdbc:db2://localhost:50000/DWCTRLDB";
Connection con;
String query ="SELECT * FROM test.employee";
Statement stmt;
try{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.print("class not found: ");
System.err.println(e.getMessage());
}
try {
con= DriverManager.getConnection(url,"db2admin","db2admin");
System.out.println("got connection");
stmt =con.createStatement();
ResultSet result =stmt.executeQuery(query);
while (result.next()) {
String name = result.getString(1) +" "+
result.getString(2);
System.out.println(name);
}
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.print("SQLException:");
System.err.println(ex.getMessage());
ex.printStackTrace();
}
}
}
The output is:
SQLException:No suitable driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:559)
at java.sql.DriverManager.getConnection(DriverManager.java:189)
I am using RAD6.0. I added jdbc drivers to java build path.
db2java.zip
db2jcc.jar
db2jcc_license_cu.jar
db2jcc_license_cisuz.jar
I configured same jars,Dburl,username,password on DbVisualizer, its working fine.So i think there is no problem with url,username and password.(I am sure).