This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Eclipse mySQL

 
shuba gopal
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ();
 
Jan Cumps
Bartender
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and



was expecting:
 
shuba gopal
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
Android Chrome Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20184
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic