Search code examples
javadatabasecsvhsqldb

How should i implement a DB in my java application locally


I'm trying to build a simple java application for my school project, and I want to be able to use a simple DB, in order to insert, update, delete and ask queries on my DB.

I need my application to run everywhere on installation, so I want to use a local DB that ships with my application, and will be accessible from inside the project, without different DB dependencies

what would be the best way to implement a local DB?

I thought of using JDBC for .csv files, which is a lot of work(?) or using HSQLDB, and create an embedded DB?

how would you implement this?

EDIT:

ok great, so I've read a little and found this SQLite tutorial,

public class Main {

    public static void main(String[] args) {
        try{
            Connection conn = DriverManager.getConnection("jdbc:sqlite: (how to set this path?)");
            Statement statement = conn.createStatement();
            statement.execute("CREATE TABLE CUSTOMERS (name TEXT,phone INTEGER,email TEXT)");


        } catch(SQLException el){
            System.out.println("somting went wrong" + el.getMessage());
        }
    }

}

now I want to set a relative path to the user folder, and set the connection on the user computer. I've noticed it's written :

o connect to an in-memory database, you use the following connection string:
jdbc:sqLite::memory

so, after setting the first connection, on my end, the DB will initialize, and then I should use the memory path when I deploy the project?


Solution

  • JDBC is a simple interface that allows you to connect to an embedded Java database. With HSQLDB you have the option of using CSV files for your data storage, as well as its SQL format script file or the binary data file.

    HSQLDB can work in a hybrid embedded / server mode to allow you to access the database using external tools.