aspose file tools*
The moose likes JDBC and the fly likes ClassNotFoundException: AS400JDBCDriver 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 "ClassNotFoundException: AS400JDBCDriver" Watch "ClassNotFoundException: AS400JDBCDriver" New topic
Author

ClassNotFoundException: AS400JDBCDriver

vikram nalagampalli
Ranch Hand

Joined: Oct 08, 2001
Posts: 91
Hi all,
I am connecting to Db2 on AS400 and i get the following error. I really appreciate some helping me on this.
java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:514)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:441)
at java.lang.ClassLoader.loadClass(ClassLoader.java:446)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java:142)
at com.howost.databasewrapper.databaseconnection.DatabaseConnection.getDB2Connection(DatabaseConnection.java:92)
at com.howost.databasewrapper.databaseconnection.DatabaseAbstract.setDB2SQL(DatabaseAbstract.java:78)
at TestDataConnect.DatabaseTestMain.main(DatabaseTestMain.java:36)
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:563)
at java.sql.DriverManager.getConnection(DriverManager.java:194)
at com.howost.databasewrapper.databaseconnection.DatabaseConnection.getDB2Connection(DatabaseConnection.java:102)
at com.howost.databasewrapper.databaseconnection.DatabaseAbstract.setDB2SQL(DatabaseAbstract.java:78)
at TestDataConnect.DatabaseTestMain.main(DatabaseTestMain.java:36)

____________________________________________________________________________
The code is as follows
___________________________________________________________________________
public class DatabaseConnection extends DatabaseAbstract
implements DatabaseConnectionInterface{


private String uri;
private String userName;
private String password;
private String server;
private String databaseName;
protected Connection conn = null;

/**
*
* Constructor to be used for connecting to Oracle or Microsoft SQL
*
*/
public DatabaseConnection(String uri, String userName, String pass)
throws SQLException{



this.uri = uri;
this.userName = userName;
this.password = pass;



}
/**
*
* Constructor to be used for connecting to AS400
*
*/
public DatabaseConnection(String server, String userName, String pass, String databaseName)
throws SQLException{
System.out.println("Database Connection !!!");

this.server = server;

this.userName = userName;
this.password = pass;
this.databaseName = databaseName;


}

/**
*
* Returns a URI String for AS400 Connection
*
*/

public String getDbUrl(){
return "jdbc:as400://" + server + "/" + databaseName + ";prompt=false";
}


/**
* Provides implementation to get the
* connection to Db2 on AS400
*
*/
public Connection getDB2Connection(){
System.out.println("Getting Coonection /n");
System.out.println("URL is !!!" + getDbUrl());

try{
System.out.println("DRIVER is !!!" + DB2_DRIVER);
Class.forName(DB2_DRIVER);


}

catch (ClassNotFoundException cnfe){
System.out.println("Error Loading DB2 Driver..../n");
cnfe.printStackTrace();
}

try {
conn = DriverManager.getConnection(getDbUrl(), userName, password);
}catch(SQLException sqle){
sqle.printStackTrace();
System.out.println("Please check the Driver information provided");
}

return conn;

}

}
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
The exception, "java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver", indicates that the JAR file containing your DB2 drivers isn't in your classpath. When you do a "Class.forName(...)" the classloader tries to find the specified class, but in your case it can't find the class.
I don't know how you are invoking your class, whether it's a client app or web application. Just make sure that your database driver class is in your classpath.
vikram nalagampalli
Ranch Hand

Joined: Oct 08, 2001
Posts: 91
Thanks for your reply wayne, I am wondering, if you can also tell me how i can set path for the DB2 drivers within WSAD 5.0.
I am trying to execute through normal client app (i.e from with the main())

Originally posted by Wayne L Johnson:
The exception, "java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver", indicates that the JAR file containing your DB2 drivers isn't in your classpath. When you do a "Class.forName(...)" the classloader tries to find the specified class, but in your case it can't find the class.
I don't know how you are invoking your class, whether it's a client app or web application. Just make sure that your database driver class is in your classpath.

[ September 30, 2003: Message edited by: vikram nalagampalli ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException: AS400JDBCDriver