I am writing a program to access a Mysql database. the database is located on a dedicated server (say server1). When i run my program from that pc (server1), setting the address to "localhost", everything is fine. but if i try to run the program from an other pc (say pc1) and set the address to server1, then is fails and i've got the following message:
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect at com.mysql.jdbc.Connection.createNewIO(Connection.java:1719) at com.mysql.jdbc.Connection.<init>(Connection.java:432) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:400) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at ClientMysql.<init>(ClientMysql.java:24) at ClientMysql.main(ClientMysql.java:33)
my first step when setting up jdbc is to use SquirrelSQL to connect to the database, and then write the code. This allows you to manage database setup and configuration problems withoiut worrying about code concerns. I think Jeanne's right though, it looks like there's something going on here which is failing before anything JDBC-related. Either database is not running, or is on a non-standard port, or the machine name is wrong or mapped to the wrong IP, or there is a firewall issue. Good luck though!