Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

connecting to mysql, with java, on a mac

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Im very puzzled.

I have a mac, and im trying to connect to mysql on localhost with java, however, it wont, and ive been good and followed the rules, but it wont work :-(

 
author & internet detective
Posts: 39986
806
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paulio,
Welcome to JavaRanch!

What error message does the program give you?
 
paulio macmurray
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the response.

the error shown is :Exception: com.mysql.jdbc.Driver

i also made a slightly different script which is below. The error message in that is my own "Cannot connect to database"

 
Sheriff
Posts: 67398
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most likely the drive isn't in the classpath.
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

paulio macmurray wrote:the error shown is :Exception: com.mysql.jdbc.Driver
i also made a slightly different script which is below. The error message in that is my own "Cannot connect to database"


Just print the exact error you are getting by printing it (ie: e.printStackTrace()) inside the catch block and post that error here? You have the JDBC Driver in your classpath?
 
paulio macmurray
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thanks for the posts.

Im also convinced that the issue is with the class path.

I have tried the following in the mac terminal:

java -cp /users/paulwhite/NetBeansProjects/bin/drivername.jar

but to no avail

Can you offer any advice as to how i can do this?
 
Vijitha Kumara
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

paulio macmurray wrote:I have tried the following in the mac terminal:
java -cp /users/paulwhite/NetBeansProjects/bin/drivername.jar


Is this the exact command you tried? Then what was the output? BTW, Did you try printing the stack trace?
 
paulio macmurray
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Just a note to let you know i managed to get the script to work, but only by dumping the connection file in the same directory as the java file, and then javac ing it in a command prompt.

Is there anyway to avoid this in netbeans?

PHEW!!!
 
Vijitha Kumara
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

paulio macmurray wrote:Just a note to let you know i managed to get the script to work, but only by dumping the connection file in the same directory as the java file, and then javac ing it in a command prompt.


If you set the classpath properly (which should includes the required jar files and the class files you are executing) no need to have them in the same place.

Is there anyway to avoid this in netbeans?


To run this inside the IDE you should set those jars in the build path of the IDE.
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic