aspose file tools*
The moose likes JDBC and the fly likes MySQL driver not getting registered Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL driver not getting registered" Watch "MySQL driver not getting registered" New topic
Author

MySQL driver not getting registered

Danish Shaukat
Ranch Hand

Joined: Nov 16, 1999
Posts: 340
Hi,

My server application is deployed on Resin 3.0 and the database is MySQL.

I am using MySQL Connector/J 3.1 JDBC driver for connecting to MySQL database.

I have tried setting the system properties and then calling DriverManager.getConnection(�) method for establishing connection.

I have also tried calling Class.forName( dbDriver ).newInstance() and then calling DriverManager.getConnection(�) method for establishing connection.

In both cases I get the exception: �No Suitable Driver Found�.

After trying out various things the following approach finally appears to work.

Class.forName( dbDriver ).newInstance()
//yes, I have to manually register the driver with the DriverManager
DriverManager.registerDriver(driver)
DriverManager.getConnection(�)

It seems as if the driver is not being registered with the DriverManager even when Class.forName(...) is being called. I can�t find an explanation for this.

Danish
[ May 05, 2006: Message edited by: Danish Shaukat ]
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
could you show the stack trace ?
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
All you need to do is specify the DataSource... if youre
using MySql connector,
the class is : com.mysql.jdbc.jdbc2.optional.MysqlDataSource

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;


MysqlDataSource dataSource = new MysqlDataSource();
Dao()
{
dataSource.setUser(usr);
dataSource.setUrl(url);
dataSource.setPassword(pswd);
dataSource.setServerName(srvr);
}

public Connection getConnection()
{

return dataSource.getConnection();

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MySQL driver not getting registered
 
Similar Threads
ways in doing database connection?
URLCLassLoader
Pls clarify my doubts on Class.forName()
Regarding Class loading
Tomcat and Mysql Configuration