Results 1 to 6 of 6
-
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:
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?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 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:
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.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
Any help woudl really be appreciated.
Thanks
- 09-25-2012, 12:43 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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.
-
Re: JDBC Connect problem on Linux: com.mysql.jdbc.Driver
I tried both:
AndJava 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#
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#
- 09-25-2012, 02:03 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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.
-
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$
- 09-25-2012, 05:36 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Similar Threads
-
Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
By santde in forum JDBCReplies: 0Last Post: 03-03-2012, 01:01 AM -
JDBC mysql driver
By Eleeist in forum New To JavaReplies: 23Last Post: 01-19-2012, 07:46 PM -
JDBC Problem - com.mysql.jdbc.Driver
By icu222much in forum Advanced JavaReplies: 5Last Post: 11-22-2011, 04:54 PM -
How to connect to any database without any JDBC driver?
By sandeep43 in forum Advanced JavaReplies: 10Last Post: 05-20-2011, 11:06 AM -
com.mysql.jdbc.Driver
By uthpalaw in forum EclipseReplies: 2Last Post: 10-14-2010, 05:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks