File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Connection to MySql Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connection to MySql Database" Watch "Connection to MySql Database" New topic

Connection to MySql Database

Indika Hewage
Ranch Hand

Joined: May 18, 2004
Posts: 35
Hi all,
I tried to run the following program and get the error message

SQLState: 08001
Message : No suitable driver

Jar file ("mysql-connector-java-3.1.10-bin.jar") is already available in the same directory where I run this program.

I get this error message when I run the command
java -classpath "e:\java_app" MySQLTest

I also setup environment variable (System variable) as

Variable name = CLASSPATH
Variable value =
C:\Program Files\Java\jdk1.5.0\bin;E:\Java_App\mysql-connector-java-3.1.10-bin.jar

What is the cause of this problem?

Thanks in advance.


Here is the source code

import java.sql.*;

class MySQLTest
{ public static void main (String args[])
{ try
Connection con = getConnection();
catch (SQLException ex)
{ System.out.println ("SQLException:");
while (ex != null) {
System.out.println ("SQLState: "+ ex.getSQLState());
System.out.println ("Message: "+ ex.getMessage());
System.out.println ("Vendor: "+ ex.getErrorCode());
ex = ex.getNextException();
catch (IOException ex) {
System.out.println("Exception: " + ex);
ex.printStackTrace ();

public static Connection getConnection()throws SQLException, IOException {

Properties props = new Properties();
String fileName = "";
FileInputStream in = new FileInputStream(fileName);

String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");

return DriverManager.getConnection(url, username, password);


Here is the property file

Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Your "jdbc.driver" value is wrong

It should be


This is the right driver string

Correct it. The program will run

Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
Indika Hewage
Ranch Hand

Joined: May 18, 2004
Posts: 35
Thanks for the reply. That is not the actual value for the drivers. We get the relevant value for "jdbc.driver" from the properties file that is "com.mysql.jdbc.jdbcDriver". So I think nothing wrong with that statement.
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
But the driver URL is

com.mysql.jdbc.Driver not com.mysql.jdbc.jdbcDriver

Correct it in ur properties file

when u download any driver for jdbc, why dont u

go through the documentation provided with the driver

u r writing the wrong URL for driver class

check this example
Indika Hewage
Ranch Hand

Joined: May 18, 2004
Posts: 35
You are absolutely correct. Thanks for that.

I agree. Here's the link:
subject: Connection to MySql Database
It's not a secret anymore!