Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

using external jar files  RSS feed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

# 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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank u Ulf ... that was exactly the problem
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!