Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MySQL driver not getting registered

 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could you show the stack trace ?
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();

}
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic