Results 1 to 6 of 6

Thread: Java Mysql Driver Error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    167

    Question Java Mysql Driver Error

    I have just installed Mysql 5 and MySQL Connector/J 5.0. I try to load driver. Here is my code.

    VB Code:
    1. import java.sql.*;
    2.  
    3. public class TestMysql
    4. {
    5.   public static void main(String args[]) throws Exception{
    6.       String driver = "com.mysql.jdbc.Driver";      
    7.       Class.forName( driver );      
    8.   }
    9. }

    Then i compiled and run. The following message display.

    VB Code:
    1. Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driv
    2. er
    3.         at java.net.URLClassLoader$1.run(Unknown Source)
    4.         at java.security.AccessController.doPrivileged(Native Method)
    5.         at java.net.URLClassLoader.findClass(Unknown Source)
    6.         at java.lang.ClassLoader.loadClass(Unknown Source)
    7.         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    8.         at java.lang.ClassLoader.loadClass(Unknown Source)
    9.         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    10.         at java.lang.Class.forName0(Native Method)
    11.         at java.lang.Class.forName(Unknown Source)
    12.         at TestMysql.main(TestMysql.java:7)

    What does it mean? I am new to Java and Mysql. Please tell me step by step to connect Java with Mysql.

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Java Mysql Driver Error

    That looks right... Have you even installed mysql??

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Java Mysql Driver Error

    Quote Originally Posted by System_Error
    That looks right... Have you even installed mysql??
    It's not that he didn't install but I beleive the problem is in the IDE he's using
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    167

    Question Re: Java Mysql Driver Error

    I have installed MySql already. I didn't use any Java IDE. I use Notepad and compile and run it in DOS Prompt.

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Java Mysql Driver Error

    Try explicitly tellling the JVM which to use:

    java -Djdbc.drivers=com.mysql.jdbc.Driver YourJavaProgram

    or something like that.

    You could also do this:

    Class.forName("com.mysql.jdbc.Driver").newInstance();


    PS: Good job on writing and compiling the real way

  6. #6
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Java Mysql Driver Error

    Code:
        public static void main(String[] args) {
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=procopio&password=alibi");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
    Works fine with me. You should check the classpath variable for the runtime to locate the class com.mysql.jdbc.Driver.

    Please see, http://vbforums.com/showthread.php?t...ight=classpath

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width