Just started working with in-memory databases. I am trying to create an in-memory DB using sqllite.
public class inMemDB {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
// TODO Auto-generated method stub
String number = "oneTwoThree";
String alphabet ="abcdef";
Connection inMemConn = null;
Class.forName("org.sqlite.JDBC");
inMemConn = DriverManager.getConnection("jdbc:sqlite::memory:");
Statement DBCreateTable = inMemConn.createStatement();
DBCreateTable.executeUpdate("CREATE TABLE sPNumbertable (String,)");
final String DBinsert = "INSERT INTO sPNumbertable VALUES(?,?)";
PreparedStatement DBAddObjects = inMemConn.prepareStatement(DBinsert);
DBAddObjects.setObject(1, number);
DBAddObjects.setObject(2, alphabet);
DBAddObjects.executeUpdate();
DBAddObjects.close();
inMemConn.close();
}
}
When I try to run the code, it throws me an near "sPNumbertable": syntax error
Follow up question: Is it also possible (as like in fileDB) to call this DB in another method. Is it as simple as replacing the the parts with file to :memory: as described here
Aucun commentaire:
Enregistrer un commentaire