LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2004, 10:02 AM   #1
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 18
java and mysql


Hi
i am trying to connect to a mysql database using java
am using the following code
Code:
try {
	Class.forName(className).newInstance();
	con = DriverManager.getConnection(driverName);
	Debugger.debugMessage(programName, "Connected");
} catch (InstantiationException e) {
	Debugger.debugMessage(programName, e);
} catch (IllegalAccessException e) {
	Debugger.debugMessage(programName, e);
} catch (ClassNotFoundException e) {
	Debugger.debugMessage(programName, e);
} catch (SQLException e) {
	Debugger.debugMessage(programName, e);
}
and i get the following error

Code:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at DbConnect.connect(DbConnect.java:83)
wht could be the problem

thanks
 
Old 06-23-2004, 04:03 PM   #2
jwstric2
Member
 
Registered: Jan 2004
Posts: 105

Rep: Reputation: 15
Either you are not registering the driver correctly, check the name being registered or the class is not actualy in the path being registered. Usally the driver is featured in a jar file which may be included in your path at run time with -da flag if my memory is right. Between me and you, you will probaly get a better response at www.javasoft.com in their forums. I'll make a bet you can a better worded solution than what I told you there.
 
Old 06-23-2004, 04:14 PM   #3
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
do you have mysql driver and jdbc librairies in your path??(both are jar files).
 
Old 06-23-2004, 06:24 PM   #4
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
both responses above are correct. If you're developing database applications in Java, however, you'll notice a dramatic improvement in reliability and performance with jdbcpool... http://www.bitmechanic.com/ (I'm not affiliated)... it kicks ass... you can make good jdbc apps without it but it keeps you writing proper code by telling you when you don't check connections in etc... it will make your life easier.

HTH

B.
 
Old 06-23-2004, 08:19 PM   #5
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
I was just playing around with JDBC and MySQL, here is my notes:

http://www.csfalcon.com/wiki/csfalcon/JDBC

Last edited by csfalcon; 06-09-2008 at 02:12 PM.
 
Old 06-24-2004, 10:59 AM   #6
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 18
thanks a lot to all of you ... i had 2 projects running in eclipse and the code was working inone and not in the other .... figured out tht was not pointing out to the jar files ...

am all set now

thanks to all of you

Last edited by linux_ub; 06-24-2004 at 11:06 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java + connection to mysql linux_ub Programming 5 03-04-2012 10:59 AM
Mysql and mysql java connector, connection refused arubin Slackware 3 03-29-2008 01:41 AM
Help me in connecting Java and Mysql deepanvenkatesh Programming 4 10-29-2005 12:34 PM
Connecting to MySQL using Java Rodotheos Programming 2 06-17-2005 07:23 AM
recordset in java, db - mysql linux_ub Programming 1 06-18-2004 03:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration