aspose file tools*
The moose likes JDBC and the fly likes connecting to mysql, with java, on a mac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connecting to mysql, with java, on a mac" Watch "connecting to mysql, with java, on a mac" New topic
Author

connecting to mysql, with java, on a mac

paulio macmurray
Greenhorn

Joined: Oct 26, 2009
Posts: 9
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Paulio,
Welcome to JavaRanch!

What error message does the program give you?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
paulio macmurray
Greenhorn

Joined: Oct 26, 2009
Posts: 9
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

Joined: Jan 10, 2002
Posts: 61198
    
  66

Most likely the drive isn't in the classpath.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

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?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
paulio macmurray
Greenhorn

Joined: Oct 26, 2009
Posts: 9
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

Joined: Mar 24, 2008
Posts: 3829

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

Joined: Oct 26, 2009
Posts: 9
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

Joined: Mar 24, 2008
Posts: 3829

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connecting to mysql, with java, on a mac