Search code examples
javamysqlconnection

MySQL ConnectException: Connection refused: connect


I'm still a beginner, I have created a JAVA program that uses a MySQL database and then turned this program into an executable jar. The database is used to store accounts for login. so when I try to log in on my main pc, (the one I used to program this project) it works normally. However, when I test this app on my friend's laptop or my second pc, it fails to connect to MySQL giving errors such as "ConnectionException: Connection Refused: connect". Someone told me that MySQL server must be installed on every pc that needs to run my program. Do you guys think this is true? and if it is true how come other programs never asked me to have a MySQL server or any other database services on my pc? I also know multiple c++ programs that are very similar to the one I created, and also with databases, that never ask for such dependencies. everything was included in their .zip I just had to run the exe and everything would work normally.

I'm looking forward to receiving a solution on what I should do to fix this problem! Thanks to everyone for your help!!! Much appreciated.


Solution

  • Not enough context but obviously your program needs a MySQL connection in order to launch. So if its service is started in your laptop (and regarding that it's local project) you have a MySQL BDD running on your dev laptop and not in your friend's one.

    In your project's configuration files, you must have reference of local MySQL url (with "localhost" host url).