File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes jdbc connection AGGRAVATION!! Can you help? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "jdbc connection AGGRAVATION!! Can you help?" Watch "jdbc connection AGGRAVATION!! Can you help?" New topic

jdbc connection AGGRAVATION!! Can you help?

DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
I have just spent the last 5 hours attempting to connect to a MySql database on my server. Everthing is working perfectly on my home machine (where I designed the servlets) but I cant get this stupid thing to connect live. Ive sent several message to the tech support section & they did send some suggestions (which I tried) but nothing has helped. Heres how the server is set up:
I have the dbs up & running fine & they have the correct tables.....everything is fine there. Im using the following to get a driver & connect:

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/[databse_name]", "[username]", "[password]");
I have confirmed the db names, username & password....they are perfect. Like I said before I know the queries are fine because the Mysql db on my local machine is set up identically to the live one. The thing thats really annoying is Im not getting any exceptions to follow! Im just not gettting the info bck frm the database! Does anyone have the slighest clue what to do next because Im just completely stumped! Any & all help is very much appreciated.....Im out of patience here!

Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
I had a similar problem. I don't know if this will help, but for some reason it worked on my machine. In the DriverMangager.getConnection(
I used my ipadress:3306
where 3306 is the port mysql is running on.
For some reason it wouldn't run when I used localhost:3306.
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Actually I think I found the problem & once again it stems back to my lack of knowledge of "real" server jvms......How I figured it out was making changes to the servlet files & uploading them to the server..nothing changed! So I got real aggravated & deleted the class files from the server. The servlet still runs about a bolt of lightning striking! The servlet is created the first time it is run in the jvm & Im pretty sure to make changes to the servlet you have to stop the JVM & restart it! Now all I have to do is figure out how to do that! Its like slamming your head on a brick wall but by god Im learning!
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
What server are you using? I'm using tomcat, and whenever I make any changes, I go through a supersticious ritual of deleting all .class files (of the files I want to change), shutdown the server, recompile the files, and then startup the server again. I'm not sure if it is necessary, but I got in the habit, and it works.
wendy hsia

Joined: Mar 01, 2001
Posts: 2
On my pc, I don't need to provide a user name and password. I don't specify mysql port number (3306), either. It works fine using statements like:
Conn = DriverManager.getConnection("jdbc:mysql://localhost/database", "", "");
Conn = DriverManager.getConnection("jdbc:mysql://localhost/database?user=root", "", "");
But when I tried to port my code over to Linux, it simply hang(i.e. wait a very long time to get an msg "the page cannot be displayed"). The Linux machine I use is a campus machine with tomcat and mysql running. I need to first login in using my own user id (i.e. wendy), and then I connect to mysql using:
>mysql -u root -p
When prompted, enter the root password. I have to connect as "root" user to have full authorities to my database.
I tried various connection statements like:
Conn = DriverManager.getConnection("jdbc:mysql://hostname:8080/database", "root", "rootpasswd");
(8080 is the port number that tomcat is running.)
It simply doesn't work!
I'm not sure whether this is the correct way to connect to mysql database using JDBC. Or is there anything I overlooked? Please advise if you have similar experience. Thank you.
I agree. Here's the link:
subject: jdbc connection AGGRAVATION!! Can you help?
It's not a secret anymore!