• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JDBC Eclipse mySQL

 
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and



was expecting:
 
shuba gopal
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 7
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 (;).
 
Sheriff
Posts: 28333
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 87
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic