File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes MySql connection issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
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
internet detective

Joined: May 26, 2003
Posts: 29219

Is the mysql driver in your runtime classpath?

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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: 3697

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

My Blog: Down Home Country Coding with Scott Selikoff
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
It is sorta covered in the JavaRanch Style Guide.
subject: MySql connection issue
Similar Threads
problem with MySQL driver
Problem with com.mysql.jdbc.Driver driver
problem with MySQL driver
Singleton Connection Class
connecting to mysql, with java, on a mac