I was going to try using JDBC and an sqlite driver to save information into a file. It seems to work fine, but I was wondering if there was a more automated way to set it up. Maybe almost like a key-value pair.
Anyway, this is what I'm doing now...
Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
Statement stat = conn.createStatement();
stat.executeUpdate("drop table if exists people;");
stat.executeUpdate("create table people (name text, age int, etc...);");
PreparedStatement prep = conn.prepareStatement(
"insert into people values (?, ?, etc... );");
for (int i = 0; i < persons.length; i++) {
prep.setString(1, persons[i].name)
prep.setString(2, persion[i].age)
....
prep.addBatch()
}
conn.setAutoCommit(false);
prep.executeBatch();
The (?,?) is kind of hacky when there are like ten fields I want to store from the class, which may change later. Counting seems very old school.
Ideally, I'd just like to go through my class and annotate which fields I'd like to store (mostly primitives like ints), but if they're objects, get the fields they annotate. Either that or something that just sits on JDBC and has a slightly faster, cleaner syntax for building the table and adding objects. This doesn't have to be persistent. It's only for rare reads and writes.