Results 1 to 6 of 6
Thread: classnotfound exception in jdbc
- 09-01-2010, 08:54 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 1
- Rep Power
- 0
classnotfound exception in jdbc
Hey guys.i am new to jdbc.i've used mysql.i installed my mysql connector/j in jdk1.6_0_11/jre/lib/ext path.I use netbeans to write my code;
Here is my code
i get this exception when runningJava Code:package jdbctrial; import java.sql.*; /** * * @author Tariq Ibrahim */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args)throws Exception { // TODO code application logic here try { Statement stmt; Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/mysql"; Connection con = DriverManager.getConnection( url,"root", ""); System.out.println("URL: " + url); System.out.println("Connection: " + con); stmt = con.createStatement(); stmt.executeUpdate( "CREATE DATABASE JunkDB"); stmt.executeUpdate( "GRANT SELECT,INSERT,UPDATE,DELETE," + "CREATE,DROP " + "ON JunkDB.* TO 'auser'@'localhost' " + "IDENTIFIED BY 'drowssap';"); con.close(); }catch( Exception e ) { e.printStackTrace(); }//end catch }//end main }//end class Jdbc11
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.j ava:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at jdbctrial.Main.main(Main.java:24)
- 09-01-2010, 01:26 PM #2
The class in the error message is not being found by the JVM. Find the jar file with that class and add it to the classpath.ClassNotFoundException: com.mysql.jdbc.Driver
- 09-02-2010, 11:23 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 31
- Rep Power
- 0
set classpath with mysql connector;
- 09-02-2010, 02:01 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
- 06-07-2011, 10:22 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Why resurrect a thread that's pushing a year old.
Especially to post something that really isn't all that good.
Your error handling leaves a lot to be desired...you are failing to print any stack traces.
You are also not closing resources ina finally block, which is likely to result in leaks.
And finally, and possibly most egregious since I point out that this is incredibly poor practice in the post just prior to yours, you suggest sticking the JDBC MySQL jar files in the JDK ext directory!
- 06-07-2011, 10:47 AM #6
Similar Threads
-
SQL exception error in JDBC conection with servlet+ jsp
By morya123 in forum New To JavaReplies: 2Last Post: 12-09-2009, 09:58 AM -
ClassNotFound exception for inner class
By hirop35 in forum New To JavaReplies: 0Last Post: 11-30-2009, 05:25 AM -
classnotfound
By mirror666 in forum New To JavaReplies: 1Last Post: 11-11-2008, 02:54 PM -
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]System Exception: Connection
By Ram_TPS in forum JDBCReplies: 1Last Post: 10-16-2008, 02:09 PM -
JDBC - Exception handling
By Java Tip in forum Java TipReplies: 0Last Post: 12-05-2007, 04:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks