I have created connection profile of MySQL in Eclipse.I have written this code:
public static void main(String[] args) {
Connection conn;
try {
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/test1";
conn= DriverManager.getConnection(url,"root","swathi");
Statement stmt= conn.createStatement();
String query="select * from sample";
System.out.println(stmt.executeQuery(query));
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
i have set the
classpath=C:\Program Files\MySQL\MySQL Connector J\mysql-connector-java-5.1.26-bin.jar
When i run the program i am getting this error:
java.lang.NoClassDefFoundError: C:\Users\swathi\workspace\project1;C:\Program
Caused by: java.lang.ClassNotFoundException: C:\Users\swathi\workspace\project1;C:\Program
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Exception in thread "main"