mercredi 6 avril 2016

Creating an in-memory Database and Table if not exist using sqllite

I am trying to create an in-memory DB using sqllite

Connection inMemConn = null;
        Class.forName("org.sqlite.JDBC");
        inMemConn = DriverManager.getConnection("jdbc:sqlite:inMemDB.db");
        Statement DBCreateTable = inMemConn.createStatement();
        DBCreateTable.executeUpdate("CREATE DATABASE IF NOT EXISTS inMemDB" );
        DBCreateTable.executeUpdate("USE inMemDB");
        DBCreateTable. executeUpdate("CREATE TABLE IF NOT EXISTS pNumbertable");

and i am trying to populate it with some Java Objects

final String DBinsert = "INSERT INTO pNumbertable VALUES(?,?)";
        PreparedStatement DBAddObjects = inMemConn.prepareStatement(DBinsert);      

        for (int i = 0; i < List.size(); i++) {
            for (int j = 0; j < List2.size(); j++) {

                DBAddObjects.setObject(1, XList.get(i)[0]);
                DBAddObjects.setObject(2, YList.get(j)[1]);
                DBAddObjects.executeUpdate();           
            }
        }

        DBAddObjects.close();
        inMemConn.close();

But, while running the code, I get the following error.

near "DATABASE": syntax error

Also, is it the correct way to create an in-mem DB.?

Aucun commentaire:

Enregistrer un commentaire