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.
Wendy