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

using external jar files

Nirmal Mekala Kumar
Ranch Hand

Joined: Aug 27, 2005
Posts: 63
I want to connect to mysql database for which i need to use "org.gjt.mm.mysql.Driver".
Can anyone please tell me in detail how to do it.
I have put both my class (which connects to database) and the Driver("org.gjt.mm.mysql.Driver") in the same directory (silly) and used the package name silly in my class.
I used the name "org.gjt.mm.mysql.Driver" in Class.forName...
then i included its path in the classpath
still i get the classnotfound exception
here is the complete error:

java.lang.ClassNotFoundException: silly.org.gjt.mm.mysql.Driver not found in [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 silly.DumpData.DumpData() (Unknown Source)
at silly.DumpData.main(java.lang.String[]) (Unknown Source)


Nirmal Kumar<br />If you have to aim, aim for the moon. Even if you miss you will land among the stars
vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
u should give code.
but i guess the problem might be cause of classpath.
or in some ide after changing classpath it reuires restart.
just check it once again.


Thanks
Vijay Saraf.
Nirmal Mekala Kumar
Ranch Hand

Joined: Aug 27, 2005
Posts: 63
this is the code

public class DumpData {
Connection con;
public DumpData(){
try
{
//System.out.println("This is beginning");
String DRIVER = "org.gjt.mm.mysql.Driver";
String userName = "root";
String password = "";
String url = "jdbc:mysql://172.16.13.96/dli";
Class.forName (DRIVER).newInstance ();
con = DriverManager.getConnection (url,userName,password); .......

I have the class file and the jar file in the same directory. and here is the .bash_profile file where i set the class path:

# User specific environment and startup programs
CLASSPATH=/home/pramod/javacode/silly:/home/pramod/javacode/silly/m.mysql-2.0.14-bin.jar
PATH=$PATH:$HOME/bin:CLASSPATH

export PATH
unset USERNAME
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
It's not complaining about not being able to find "org.gjt.mm.mysql.Driver", it's complaining about not being able to find "silly.org.gjt.mm.mysql.Driver", so I think you have a problem with your path/classpath setup.
[ September 01, 2005: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Nirmal Mekala Kumar
Ranch Hand

Joined: Aug 27, 2005
Posts: 63
I have set the path till the jar filename and i have not used silly as a package. So why would it search as silly.org....
Nirmal Mekala Kumar
Ranch Hand

Joined: Aug 27, 2005
Posts: 63
Guys .... solved my problem. Though it is a lumberjack's solution ( i extracted the jar to the current directory) i dont have time.
But if anyone does understand the problem please keep posting. This is not the first time i got this problem and i want to know the complete solution
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
# User specific environment and startup programs
CLASSPATH=/home/pramod/javacode/silly:/home/pramod/javacode/silly/m.mysql-2.0.14-bin.jar
PATH=$PATH:$HOME/bin:CLASSPATH


Why would you add CLASSPATH to your PATH? Mixing is two is not a good idea.
Not that it would work in this case, since you are missing the "$" in front of it.
[ September 01, 2005: Message edited by: Ulf Dittmer ]
Nirmal Mekala Kumar
Ranch Hand

Joined: Aug 27, 2005
Posts: 63
thank u Ulf ... that was exactly the problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using external jar files