0

I am looking for a way to save an SQL database and then reference it by means other than localhost which would not work because it is being used on other computers.

I realize that my terminology may not be correct in asking for a means to "package" an SQL database however I am not very sure how to put my desire such a concise title. I have a database that I created through mySQL here: http://gyazo.com/fcac155a60c0d2587442c3e4807ef98a

I can access this database with no problems through the following code...

try
        {
                //Get connection
                Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/term_database","root", "_cA\"#8X(XHm+++E");        

                //**********
                //Connection myConn = DriverManager.getConnection("jdbc:mysql:translationDatabase","root", "_cA\"#8X(XHm+++E");
                //**********

                //create statement
                Statement myStmt = myConn.createStatement();

                //execute sql query
                ResultSet myRs = myStmt.executeQuery("select * from terms WHERE idNumber=" +termNumber);

                //process result set
                while(myRs.next()){
                    term= (myRs.getString(language));
                }
            }
            catch (Exception exc)
            {
                exc.printStackTrace();
            }

However, I assume that my users will be on different computers and so a "//localhost" reference will not work. They do not have access to the internet either. So I aim to include the database in my program's files to be downloaded with the software or to include it in the jar. I was not able to find any means to do that online. The code I surrounded with *'s was an attempt to reference translationDatabase.sql which I saved through the program mySQL into my software's directory but it did not work as shown here: http://gyazo.com/e9d4339435dedecab4e7ad960e9b13b6

To recap: I am looking for a way to save an SQL database and then reference it by means other than localhost which would not work because it is being used on other computers.

mrVentures
  • 121
  • 1
  • 8
  • maybe you can use sqlite instead? – Jasen Dec 27 '14 at 04:35
  • I'm not sure. But isn't there just a way to embed a SQL database so I don't need to access it through the local host but rather through a local reference? – mrVentures Dec 27 '14 at 06:29
  • that sould be interpreted in an number of different ways, but the only one that makes any sense is use sqlite. – Jasen Dec 27 '14 at 06:55

1 Answers1

0

The idiomatic terminology is "embedded" or "serverless" database.

There are several pure-java solutions. There is also the popular SQLite, which you can manipulate via its command line client, or via a third-party JDBC driver (example 1, example 2)

Any of the above solutions will require that you convert your existing MySQL database to the target system..

Alternatively, you may consider bundling your application with MySQL server (possibly with an automated installation process, so that installation is invisible to the end-user).

Community
  • 1
  • 1
RandomSeed
  • 29,301
  • 6
  • 52
  • 87
  • Thank you for your help. I have elected to use SQLite and am currently working to make that happen. Your advice has helped gear me into that direction and I am grateful for it. – mrVentures Dec 28 '14 at 20:09