wood burning stoves*
The moose likes JDBC and the fly likes JDBC Eclipse mySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Eclipse mySQL" Watch "JDBC Eclipse mySQL" New topic
Author

JDBC Eclipse mySQL

shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
Hi

I am learning JDBC using Eclipse.

For the following code



I am getting the following error:



Based on previous posts with this error message, I tried setting the J Connector jar file in Java Build Path. I used the eclipse tutorial as reference - http://www.vogella.de/articles/Eclipse/article.html#classpath.

But I am still getting this error. Do I need to explicitly set the class path anywhere else? Please tell me if there is anything else that I can try.

Thanks
Shuba
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

I tried setting the J Connector jar file in Java Build Path
That is where Eclipse looks when compiling your code. You should try to set the Java Run Path.


... and drop the newInstance call. It should not be there.
Class.forName ("com.mysql.jdbc.Driver"). newInstance ();


OCUP UML fundamental and ITIL foundation
youtube channel
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

... and



was expecting:
shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
Hi Jan,

Thanks for the response. I am not able to find a Java Run Path any where in the Project=>Properties window. Can you please tell me how to access this variable?

Thanks
Shuba
Grayson Churchel
Greenhorn

Joined: Aug 20, 2011
Posts: 7

I'm not certain, but I suspect that Jan is talking about your CLASSPATH environment variable. If you're on Windows you can go to your System Properties window, click on Environment Variables then on you CLASSPATH variable.
You can view it from a command prompt by entering the command:
> ECHO %CLASSPATH%

Again, I'm not sure that what was meant but give it a shot. You may want to save a copy of that variable before you start changing it. It's a list of folders on your system delimited by semi-colons (;).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

However in Eclipse you don't have to fool around with the CLASSPATH environment variable. You just have to set your project's build path appropriately.

To me that error message looks like whatever you put into the build path claiming to be the Connector/J jar file isn't a jar file.
shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
Thank you all for your suggestions. Finally the program runs without this error.

I downloaded the jar multiple times and used it in the build path. Still got the same error.

So after some googling I found that sometimes the error goes away if new Java updates are installed.

So I installed java 7(had Java 6 previously) and the latest version of Eclipse and it works!!

So the changes I made are:

1) Latest version of Java and Eclipse
2) Download the rar file for Connector J from MySql.org and extract the entire file into Eclipse workspace.
3) Java Build Path - Add external jar- add the above jar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Eclipse mySQL
 
Similar Threads
My applet is not being seen in its jar anymore. Please help!
Applet not loading due to IOException
executable jar build by JBuilderX, NoClassDefFoundError!!
Error whiile using JBoss Tool with eclips
Problem loading applet from servlet - load: xxx.class not found