learn java
The moose likes JDBC and Relational Databases and the fly likes mysql connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "mysql connection problem" Watch "mysql connection problem" New topic

mysql connection problem

ashok kandaswamy

Joined: Aug 19, 2008
Posts: 16
hi all ,
i am trying to connect mysql Db by this code ,

import java.sql.*;
//import com.mysql.jdbc.Driver;

public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
System.out.println("Disconnected from database");
} catch (Exception e) {

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at MysqlConnect.main(MysqlConnect.java:15)

but while executing this i got this exception....?

please help me..it's urgent..

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41601
Originally posted by ashok kandaswamy:
..it's urgent..

Read this; it's no more urgent than anybody else's question.

Where have you put the connector/J jar file and have you included it in your classpath when running that class?
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: mysql connection problem