• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connecting to mysql, with java, on a mac

 
paulio macmurray
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 :-(

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • 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"

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most likely the drive isn't in the classpath.
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • 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: 3914
9
Chrome Fedora Hibernate
  • 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: 3914
9
Chrome Fedora Hibernate
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic