0

I am having a project in which I am using a database. I pretty much finished the project except that I need to make a *.jar file from it. I have a MySQL database on my localhost and whenever I start the *.jar file on my laptop it works perfectly fine. But, the *.jar file is going to be on another computer and that computer doesn't have the database that I made on my computer.

I am using the following to connect to the database on my computer:

Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/database","root"," ");
            st = con.createStatement();
            rs = st.executeQuery("select * from program");

So the question is, is there a way that I can export the mySQL database and then change some stuff in the code so that the database could be accessed? Do I need a remote server to do this? How can I make the database be portable and work on another computer?

Thank you all for your time :)

1 Answers1

0

Embedding mysql is terrible idea, as mysql as commonly used to persist data,

not like the h2 or redis (memory based database)

if u embed a mysql then you will at least need to manually write the data in your java file, and keep writing on in order to keep the data sync and fresh,and data that inserted in runtime will be lost.

i recommend just host your mysql server in remote server, then use connect to it using jdbc

thats way more easier and will safe your life

hope this helps

rizesky
  • 424
  • 6
  • 13