0

I have created a standalone application as a school project. The major problem we are encountering is that since it has Java as front-end and MySQL as back-end (compulsory), and we have created a database that solely belongs to one computer, we cannot run the same project on different machines because it won't have the required database, the tables, or the same username and password we used to connect to MySQL.

So my question is **How can I connect to MySQL server in different Machines? **

For database and Tables, I could run a sql file, but that will happen when I would be connected to the MySQL server. Also I am developing the project at my home computer, and I want to run the project on different computers who are connected to my computer by no means .

Manu
  • 9
  • 1
  • Why would you like to connect from different machines to mysql server? Would you like to distribute the backend or something else? – Christos Papoulas Jan 25 '16 at 15:10
  • Is your MySQL instance only deployed on one local machine? Or is this deployed on a school server somewhere? – Daryl Bennett Jan 25 '16 at 15:14
  • I would like to redistribute the complete project having java as front end and MySQL as back-end. The java program won't run as it is connected to tables and database in my computer which won't be present in someone else's computer. And I couldn't create the database and the tables in their computer because I don't have their username or password to the MySQL server... – Manu Jan 25 '16 at 15:14
  • @DarylBennett no, it is deployed on my home machine, and I would like to run it on one of the school machines or anywhere my sir like :) – Manu Jan 25 '16 at 15:15

3 Answers3

1

You a following options

  1. Shared drive : Attach database stored on remote shared drive to a local SQL Server read here

  2. Connect to remote SQL Server instance from local computer - better if they are in same LAN - Steps here

  3. If you want to package DB with app where you have predefined data and you dont want to save transactional data - use inMemory DB. They will load when you application starts up.

Sheetal Mohan Sharma
  • 2,908
  • 1
  • 23
  • 24
  • Personally agree with option 2. Deploy your MySQL instance on a server, and have everyone in your group connect the Java app to that. That way, anybody, anywhere can connect. Your data will be centralized and synced. – Daryl Bennett Jan 25 '16 at 15:18
  • Could I create database and tables by running an SQL file along with installation of my project? Could I do that even if I don't know the machines mysql server's username and password? – Manu Jan 25 '16 at 15:22
  • You need to setup MySQL instance and if required update the default credentials or add a new account. Check this http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html – Sheetal Mohan Sharma Jan 25 '16 at 15:35
0

Instead of using localhost in your database connection string, you should use the ip or aname of the database host

e.g.

jdbc:mysql://IP:3306/db?user=user&password=password

jdbc:mysql://A-NAME/db?user=user&password=password

Just make sure that port 3306 is open and that you have access on the system the databasse is hosted on

George Artemiou
  • 3,076
  • 2
  • 19
  • 36
0

Already your application can work using different machine.

You have only to change the localhost string in your connection string with the IP of the MySQL machine :

DriverManager.getConnection("jdbc:mysql://localhost/database?"+ "user=sqluser&password=sqluserpw");

And make sure that remote access are enabled in your MySQL configuration. You can find more about it here.

Community
  • 1
  • 1
Wael Sakhri
  • 397
  • 1
  • 8