| Author |
class loader problem during connection of MySql driver
|
Madhawi Maurya
Ranch Hand
Joined: Aug 22, 2007
Posts: 42
|
|
My program is: import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; class First { public static void main(String args[]) throws Exception { Statement stmt = null; ResultSet rs = null; Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://localhost/plantshop?user=root & password = mad"); stmt = con.createStatement(); rs = stmt.executeQuery("select * from Plant"); while(rs.next()) { System.out.println(rs.getInt(1)); } } catch(SQLException ex) { System.out.println(ex); } catch(Exception ex) { ex.printStackTrace(); } } } Run Time Error: java.lang.ClassNotFoundException: com.mysql.jdbc.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 First.main(First.java:16) Please help me, what is the problem and how will solve?
|
SCJP1.5 with 90%
|
 |
Freddy Wong
Ranch Hand
Joined: Sep 11, 2006
Posts: 959
|
|
|
Have you included the driver in the classpath?
|
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
|
 |
Madhawi Maurya
Ranch Hand
Joined: Aug 22, 2007
Posts: 42
|
|
Originally posted by Freddy Wong: Have you included the driver in the classpath?
I have included this driver in the classpath: C:\Java\jdk1.5.0_01\bin\mysql-connector-java-5.0.3-bin
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
It should be a jar. Add an entry in CLASSPATH envirinment variable or if you are using and IDE then refer to its documentation to find out as how an external class library be added.
|
Rahul Bhattacharjee
LinkedIn - Blog
|
 |
Madhawi Maurya
Ranch Hand
Joined: Aug 22, 2007
Posts: 42
|
|
Originally posted by Rahul Bhattacharjee: It should be a jar. Add an entry in CLASSPATH envirinment variable or if you are using and IDE then refer to its documentation to find out as how an external class library be added.
I am using Eclipse. Eclipse is new for me. Is there any other method to set classpath
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
Originally posted by Madhawi: I am using Eclipse. Eclipse is new for me. Is there any other method to set classpath
Make a runtime of Java Applications type and go to classpath and then add external jars. Please check with the Javarnach's naming policy. http://www.javaranch.com/name.jsp
|
 |
Madhawi Maurya
Ranch Hand
Joined: Aug 22, 2007
Posts: 42
|
|
Originally posted by Rahul Bhattacharjee: Make a runtime of Java Applications type and go to classpath and then add external jars. Please check with the Javarnach's naming policy. http://www.javaranch.com/name.jsp
Thanks, to solve my problem. I Added external jar file. now i got another problem. Help me. i am getting error: java.sql.SQLException: Access denied for user ''root''@'localhost' (using password: NO) what is the problem?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
|
Madhawi, please check your private messages for an important message from JavaRanch. You can see your private messages by clicking My Profile.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
Mahadewi... Your display name is still not according to the JavaRanch naming policy. Please read the naming policy carefully and change your name immediately.
|
 |
Medha Jhunjhunwala
Greenhorn
Joined: Sep 06, 2007
Posts: 9
|
|
you should give access to the client host in the mysql server -Medha
|
 |
 |
|
|
subject: class loader problem during connection of MySql driver
|
|
|