aspose file tools*
The moose likes JDBC and the fly likes java.sql.SQLException: No suitable driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: No suitable driver" Watch "java.sql.SQLException: No suitable driver" New topic
Author

java.sql.SQLException: No suitable driver

prajwala solanki
Greenhorn

Joined: Jul 17, 2007
Posts: 9
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).
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
Whish jar has the class COM.ibm.db2.jdbc.app.DB2Driver ?? Check that this class/jar is in the classpath.


Amit Tank
Linked In
prajwala solanki
Greenhorn

Joined: Jul 17, 2007
Posts: 9
db2java.zip
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: No suitable driver