#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    40
    Rep Power
    14

    JDBC loading driver problem.......


    can anyone offer some guidance on a problem to do with JDBC connectivity to MySQL server.

    I have:
    MySQL server 5.0
    jdk1.5.0....
    and the 'mysql-connector-java-3.1.12'

    and i have written a small test java file to load the drivers and connect to the test table set up automatically in MySQL. All i want it to do is load drivers, connect and return yes for each.

    I keep getting the 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.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at TestMysql.main(TestMysql.java:14)

    when trying to build. Now i know about setting the class path to the jar file inside 'mysql-connector-java-3.1.12' and i have done this but i reckon ivfe set that bit up wrong. im on XP and have gone into start/control panel/system/advanced/environment variables and created a new system variable:
    "variable name: CLASSPATH"
    "variable value: .;C:\Program Files\MySQL\mysql-connector-java-3.1.12\mysql-connector-java-3.1.12-bin.jar"

    That is exactly what i have entered when setting the classpath.

    any quick help would be hugely appreciated!!!
    thank you
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,419
    Rep Power
    1718
    Try to put it in a path with no spaces. Spaces seem to mess up the classpath.
  4. #3
  5. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,040
    Rep Power
    1291
    Try changing the CLASSPATH to this

    Code:
    .;C:\Progra~1\MySQL\mysql-connector-java-3.1.12\mysql-connector-java-3.1.12-bin.jar
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    40
    Rep Power
    14
    firstly, thanks alot for the help however the exact same issue is occuring. neither solutions you have suggested work.

    is there more things i need in place to set this up i.e. is the following all i need:

    MySQL server 5.0
    jdk1.5.0
    mysql-connector-java-3.1.12

    I do have a JRE installed as well would this create any conflicts???

    thanks for the help
  8. #5
  9. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    Are you using an IDE? Most -- if not all -- IDEs will ignore the system classpath (which is one reason I don't bother to set one). If you are using an IDE, you'll need to configure the build and runtime paths within the IDE.

    Hope this helps!


    P.S. Welcome to the forum!

    ~
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    40
    Rep Power
    14
    yea im using Jcreator to open and compile and build the file!

    How else can i do it, store it as a class file or java file? and then run it from command prompt?

    if this is correct please could you tell me the command i would be very grateful.

    thank you again
  12. #7
  13. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    You can compile and run it from JCreator if you add the JAR to the build/run path. Check your documentation for JCreator for how to do that. If you want to compile or run from the command line, you can simply add the classpath by using the -classpath or -cp options. For detailed information regarding these options, check out the following:

    javac - Java programming language compiler
    java - the Java application launcher
    How Classes are Found
    ~
    Last edited by Yawmark; February 3rd, 2006 at 11:01 AM.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    40
    Rep Power
    14
    using your advice about the IDE I have sorted this issue in as far as it all works now in the ide, as i set the jar file into the project lib directory.

    SO thank you very much for helping me there. However in terms of command line prompt, i opened up a terminal and this was the result:

    C:\Documents and Settings\Shaun\Desktop>javac -TestMysql.class

    'javac' is not recognized as an internal or external command,
    operable program or batch file.


    I am very unfamiliar with compiling from a terminal so any offers of help would be greatly appreciated, and thank you for your time in helping me within the IDE

    What a great site!
  16. #9
  17. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,040
    Rep Power
    1291
    You need to make sure that the bin directory of the JDK installation is in your PATH or use the absolute pathname.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    40
    Rep Power
    14
    thanks very much for your assistance its much appreciated

IMN logo majestic logo threadwatch logo seochat tools logo