It's not a secret anymore!
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 REST with Spring (video course) this week in the Spring 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) {


at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at MysqlConnect.main(

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

please help's urgent..

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45286
Originally posted by ashok kandaswamy:'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?
I agree. Here's the link:
subject: mysql connection problem
jQuery in Action, 3rd edition