-1

I have a java project. It use MySQL database transactions. I would run this java project in the another computer. I would making a setup. In this setup need to be import the .sql data file. But MySQL must be. And i don't would install MySQL in the another computer. I would put the MySQL server file in the setup.

How can i do?

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
SOF JMP
  • 21
  • 5
  • Please [edit] your question to give more information. Will your users (the ones running your setup program) use their own MySQL servers to run your Java program? Will several users share the same MySQL server with each other? Will the MySQL server always be on a different machine from your Java program? – O. Jones Feb 24 '17 at 13:50

3 Answers3

1

Instead to use localhost connection like this :

Connection connection = DriverManager.getConnection(
                    "jdbc:somedb://localhost/databasename", "username", "password");

You can use the @IP of the other computer or server for example 10.6.99.122, so this can solve your problem and not need to install or import your sql file in the other computers:

Connection connection = DriverManager.getConnection(
                    "jdbc:somedb://10.6.99.122/databasename", "username", "password");

EDIT

You can learn more about embedded database here Java, MySQL: Is there a way to embed a MySQL server with a Java program? and here Embedding mysql in java desktop application and also here

Community
  • 1
  • 1
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
0

You either use external connection and host your database to a web hosting, or if you don't need to share the data and the data is locally stored and generated by the user himself, then you can use sqlite file instead. Your question should explain more about the type of data and how will be used so that we give you the best solution.

0

If you hope your customers will run your Java program on their computers and connect it to their MySQL servers, you must put your database connection string into a Java properties file. You have no choice about this. You must allow your customers to set their own connection string values.

Connection strings are used to make new JDBC connections. They usually look something like this:

jdbc:mysql://mysql1.datacenter.example.com:3306/sofjmp?user=username&password=xxxxxsx

You can include the user's database username and password secrets in the connection string you store in the properties file. That gives your customers a way to specify their own database credentials.

Your setup program should include instructions for users about setting that connection string property. You can also include your .sql file with your table definitions in your setup program. You can instruct your customers to run the .sql file when they first set up your program.

O. Jones
  • 103,626
  • 17
  • 118
  • 172