Dear all,
I want to connect the my mysql database in the below java program.But i could not able to connect the myslq database.
i have downloaded the below jar file and put the jar file in the below path.
Jar File:
=========
mysql-connector-java-5.0.8-bin.jar
Path:
====
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/lib
mysql version
=============
SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.0.77 |
+-----------+
CODING
======
import java.sql.*;
public class testsql{
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 = "password";
try {
Class.forName(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) {
System.out.println("cannot connect to database ");
e.printStackTrace();
}
}
}
Error:
=====
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at testsql.main(testsql.java:13)
Can any one say what i missed in the above program.
I have compiled the program successfully .
But i could not able to run the program.
Thank you,
With Regards,
Prem