It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes MySql connection issue 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 "MySql connection issue" Watch "MySql connection issue" New topic

MySql connection issue

kittu karan
Ranch Hand

Joined: Mar 09, 2008
Posts: 63
I wrote below code
import java.sql.*;
public class JdbcConnection {
public static void main (String[] args)
String userName = "root";
String password = "admin";
//String url = "jdbc:mysql://localhost:3306/test";
String url="jdbc:kiran";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection (url,userName ,password );
System.out.println ("Database connection established");
}catch (Exception e)
System.err.println ("Cannot connect to database server");

I created DSN name as kiran using MySQL ODBC 3.51 Driver.
No compilation error occuring but runtime error is occuring like

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
other exception regarding url and classloader
whether I have to set any jar files.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32803

Is the mysql driver in your runtime classpath?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
kittu karan
Ranch Hand

Joined: Mar 09, 2008
Posts: 63
No, I don't have.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3749

Download it from the MySQL website. Just search google for: mysql java connector.

[OCA 8 Book] [Blog]
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by kiran peruka:
No, I don't have.

then you should have.

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
I agree. Here's the link:
subject: MySql connection issue
It's not a secret anymore!