File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes sql connection with java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sql connection with java" Watch "sql connection with java" New topic
Author

sql connection with java

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
I've formatted my linux machine.After that I have downloaded mysql-connector-java-3.0.10-stable.tar.gz.I've put java in the path:usr/share/java.Inside this i am having jre.I dont have jdk.now when i am running a program,it shows the following error.where should i put mysql jar file.Am i going correct?
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found in [file:/usr/share/java/libgcj-3.4.3.jar, file:./, core:/]
at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.5.0.0)
at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at Connect1.main(java.lang.String[]) (Unknown Source)
Thanks.
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by preethi Ayyappan:
I've formatted my linux machine.After that I have downloaded mysql-connector-java-3.0.10-stable.tar.gz.I've put java in the path:usr/share/java.Inside this i am having jre.I dont have jdk.now when i am running a program,it shows the following error.where should i put mysql jar file.Am i going correct?
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found in [file:/usr/share/java/libgcj-3.4.3.jar, file:./, core:/]
at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.5.0.0)
at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at Connect1.main(java.lang.String[]) (Unknown Source)
Thanks.




Better you put it inside

usr/share/java
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thank you for your reply.I've put the mysql-connector-java-3.0.10-stable.tar.gz,mysql-connector-java-3.0.10-stable-bin.jar
inside usr/share/java.Now also its showing the same error
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

First of all, the .tar.gz file is an archive file. You need to unpack it with tar:

tar xf mysql-connector-java-3.0.10-stable.tar.gz

One of the unpacked files will be a JAR file. It doesn't matter in which directory you put that JAR file; what you need to do is include it in your classpath. When you run your program, do it like this (note: this is just an example, you'll have to fill it in correctly yourself):

java -cp /some/path/mysql-connector-java-3.0.10-stable-bin.jar:. com.mypackage.MyMainClass

Also, note that you are using GCJ (GNU Java) instead of Sun Java. GNU Java is the version of Java that comes with most Linux distributions because it is fully open source. However, it is unfortunately an incomplete and slow implementation of Java. It's much better to download and install Sun Java on your Linux system. Lookup in the documentation of your Linux distribution how to install Sun Java.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
I have an doubt.whether i have to put the Connect1.java inside com.mypackage?i've tried like this.
java -cp /usr/share/java/mysql-connector-java-3.0.10-stable-bin.jar:. com.mypackage.Connect1
I found the following error
Exception in thread "main" java.lang.NoClassDefFoundError: com.mysql.Connect1
at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)
at _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.5.0.0)
at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.5.0.0)
at __gcj_personality_v0 (/root/Desktop/backup/java.version=1.4.2)
at __libc_start_main (/lib/tls/libc-2.3.4.so)
at _Jv_RegisterClasses (/root/Desktop/backup/java.version=1.4.2)
inside /usr/share/java,I am having the mysql jar file and i've extracted that.there is a folder com.inside that whether i have to create a folder and put the java file?
[ December 20, 2007: Message edited by: preethi Ayyappan ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sql connection with java