aspose file tools*
The moose likes JDBC and the fly likes mysql connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "mysql connection problem" Watch "mysql connection problem" New topic
Author

mysql connection problem

ashok kandaswamy
Greenhorn

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 {
//Class.forName(driver).newInstance();
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}

----------------------------------------------------------------------
exception:
------------------------------
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..


Sk.Ashokkumar.....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: mysql connection problem