Hi
I have done all the codings part for connecting mysql with java in eclipse environment.
Coding Part:
import java.sql.Connection;
import java.sql.DriverManager;
public class MysqlConnect {
public static void main(String[] args)throws Exception{
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3309/";
String dbName = "ananthu";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "sa";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url+dbName,userName,pa ssword);
System.out.println("Connected to the database");
System.out.println();
conn.close();
System.out.println("Disconnected from database");
} catch (java.lang.ClassNotFoundException e) {
//System.out.println("Could not connect");
e.printStackTrace();
}
}
But when i run as java application the following are the errors i get,
Result after executing is:
MySQL Connect Example.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at MysqlConnect.main(MysqlConnect.java:15)
What can i do to get the output?
But when this coding is executed seperately in java application wihtout using Eclipse environment i get the output correctly.
Please give me the procedures for connecting mysql with java application in eclipse environment...