• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to connect to mySQL DB.

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Apologies if this question is asked a lot (I have used the search but couldn't find anything!)

I'm trying to connect to a mySQL database using the following code, but I keep getting a ClassNotFoundException: com.mysql.jdbc.Driver error.
I think it may be a problem with the mysql connector needing to be in the classpath, but as I intend to use migLayout, I need the classpath to be pointing to that.
My current classpath is ".;L\My Projects\MyJavaApps\miglayout-3.7"

I've added the 'mysql-connector-java-5.1.7-bin' file to the above folder in the hope that would satisfy it's need to be in the classpath, but it looks like it doesn't.

Any help/ pointers would be greatly appreciated!

Many thanks!

My code:


Full error message:
 
John Pisci
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've set the classpath as "...mysql-connector-java-5.1.7-bin.jar" and now it works.

However, I'm using miglayout in my application and the miglayout folder needs to be added to classpath for it to work.
I've tried adding the mysql-connector-java-5.1.7-bin.jar the miglayout folder and pointed the classpath to .jar. I can connect to the db this way, but cannot launch my miglayout application.
I then tried pointing the classpath to the miglayout folder (which has the .jar file in) and the miglayout app works, but I cannot connect to the db.

I know I'm doing something wrong, so how can I set it so I can have both working?

Thanks!

 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How exactly are you running the application?

If as plain Java class using java.exe, you need to set the classpath using -cp or -classpath argument.
If as JAR file using java.exe -jar, you need to set the classpath in the manifest file.
 
John Pisci
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!

I didn't realise I could have more than 1 filepath in the classpath.

I've been stuck on that all day!
reply
    Bookmark Topic Watch Topic
  • New Topic