• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mysql connection problem

 
ashok kandaswamy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic