Results 1 to 6 of 6
  1. #1
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    18
    Blog Entries
    1
    Rep Power
    0

    Default JDBC Connect problem on Linux: com.mysql.jdbc.Driver

    Hi All,
    I have a simple java application which reads data from the DB. The application works fine on windows. I have added the 'mysql-connector-java-5.1.22-bin.jar' in my windows classpath.
    The problem comes when i copy the application on linux and run it. I getthe following exception:

    Java Code:
    root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# javac LCPAnalyzer.java
    root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# java LCPAnalyzer
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
            at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:186)
            at LCPAnalyzer.connectDB(LCPAnalyzer.java:47)
            at LCPAnalyzer.main(LCPAnalyzer.java:32)
    I have read various articles on setting classpath in linux, but couldn't get through and I am still unclear as to how to set the classpath in linux?

    I even copied the 'mysql-connector-java-5.1.22-bin.jar' in my project src folder where the .class file is generated but still no success.

    I also tried setting the classpath at runtime by: export CLASSPATH=/opt/integra/middleware/LCPAnalyzer/src/mysql-connector-java-5.1.22-bin.jar

    but then i got the follwoing exception:

    Java Code:
    root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# javac LCPAnalyzer.java
    root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# java LCPAnalyzer
    Exception in thread "main" java.lang.NoClassDefFoundError: LCPAnalyzer
    Caused by: java.lang.ClassNotFoundException: LCPAnalyzer
    I am totally lost as how to proceed now. Could someone please suggest a permanent way to set classpath in linux. I have few other java mail api related jars as well, which i would want to set in the classpath in linux but first want to resolve this mysql connector problem.

    Any help woudl really be appreciated.

    Thanks

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: JDBC Connect problem on Linux: com.mysql.jdbc.Driver

    java -cp <path to jar file>;. LCPAnalyzer

    It is generally not a good idea to set the system path.
    If your export is just for the console session then you need to add the '.' part which represents the current directory.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    18
    Blog Entries
    1
    Rep Power
    0

    Default Re: JDBC Connect problem on Linux: com.mysql.jdbc.Driver

    I tried both:

    Java Code:
    root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# java -cp /opt/integra/middleware/LCPAnalyzer/src/mysql-connector-java-5.1.22-bin.jar;. LCPAnalyzer
    Usage: java [-options] class [args...]
               (to execute a class)
       or  java [-options] -jar jarfile [args...]
               (to execute a jar file)
    where options include:
        -d32          use a 32-bit data model if available
        -d64          use a 64-bit data model if available
        -server       to select the "server" VM
                      The default VM is server.
    
        -cp <class search path of directories and zip/jar files>
        -classpath <class search path of directories and zip/jar files>
                      A : separated list of directories, JAR archives,
                      and ZIP archives to search for class files.
        -D<name>=<value>
                      set a system property
        -verbose[:class|gc|jni]
                      enable verbose output
        -version      print product version and exit
        -version:<value>
                      require the specified version to run
        -showversion  print product version and continue
        -jre-restrict-search | -jre-no-restrict-search
                      include/exclude user private JREs in the version search
        -? -help      print this help message
        -X            print help on non-standard options
        -ea[:<packagename>...|:<classname>]
        -enableassertions[:<packagename>...|:<classname>]
                      enable assertions with specified granularity
        -da[:<packagename>...|:<classname>]
        -disableassertions[:<packagename>...|:<classname>]
                      disable assertions with specified granularity
        -esa | -enablesystemassertions
                      enable system assertions
        -dsa | -disablesystemassertions
                      disable system assertions
        -agentlib:<libname>[=<options>]
                      load native agent library <libname>, e.g. -agentlib:hprof
                      see also, -agentlib:jdwp=help and -agentlib:hprof=help
        -agentpath:<pathname>[=<options>]
                      load native agent library by full pathname
        -javaagent:<jarpath>[=<options>]
                      load Java programming language agent, see java.lang.instrument
        -splash:<imagepath>
                      show splash screen with specified image
    See http://java.sun.com/javase/reference for more details.
    -bash: LCPAnalyzer: No such file or directory
    root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src#
    And

    Java Code:
    root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# java -cp /opt/integra/middleware/LCPAnalyzer/src/mysql-connector-java-5.1.22-bin.jar. LCPAnalyzer
    Exception in thread "main" java.lang.NoClassDefFoundError: LCPAnalyzer
    Caused by: java.lang.ClassNotFoundException: LCPAnalyzer
            at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
    Could not find the main class: LCPAnalyzer. Program will exit.
    root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src#

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: JDBC Connect problem on Linux: com.mysql.jdbc.Driver

    What is the contents of that directory?
    Is there an LCPANalyzer.class file?
    Because that error is implying there isn't:
    "-bash: LCPAnalyzer: No such file or directory"

    You can shorten the command if the jar file is in the current directory:
    java -cp <jar file name>;. LCPAnalyzer

    The second example is not valid for the classpath you want to use.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    18
    Blog Entries
    1
    Rep Power
    0

    Default Re: JDBC Connect problem on Linux: com.mysql.jdbc.Driver

    I fianlly managed to resolve that problem by setting the class path in /etc/profile file:

    Java Code:
    export PATH
    JAVA_HOME="/usr/lib/java"
    export JAVA_HOME
    
    CLASSPATH="/java/classes:/opt/integra/middleware/LCPAnalyzer/bin/mysql-connecto$
    export CLASSPATH=$CLASSPATH:/java/classes:/opt/integra/middleware/LCPAnalyzer/b$

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: JDBC Connect problem on Linux: com.mysql.jdbc.Driver

    Which now means every java program you try and run will use that class path...

    (and apologies for missing out that Linux needs a colon, not a semi-colon...I always forget that one)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 03-03-2012, 01:01 AM
  2. JDBC mysql driver
    By Eleeist in forum New To Java
    Replies: 23
    Last Post: 01-19-2012, 07:46 PM
  3. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Advanced Java
    Replies: 5
    Last Post: 11-22-2011, 04:54 PM
  4. How to connect to any database without any JDBC driver?
    By sandeep43 in forum Advanced Java
    Replies: 10
    Last Post: 05-20-2011, 11:06 AM
  5. com.mysql.jdbc.Driver
    By uthpalaw in forum Eclipse
    Replies: 2
    Last Post: 10-14-2010, 05:09 AM

Posting Permissions

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