I'm trying to store all the items that were created in the ITEM
table and I wonder if I can do that:
PreparedStatement stm = null;
//String sql = "INSERT INTO ITEM (ID, TYPE, TITEL, UITGELEEND) VALUES ('%s', '%s', '%s', %b)";
try {
stm = db.prepareStatement("INSERT INTO ITEM (ID, TYPE, TITEL, UITGELEEND) VALUES (?, ?, ?, ?)");
for (int n = 0; n < ItemLijst.getItems().size(); n++) {
Item huidigItem = ItemLijst.getItemObvIdx(n);
stm.setString(1, huidigItem.getID().toString());
stm.setString(2, huidigItem.getType().toString());
stm.setString(3, huidigItem.getTitel());
stm.setString(4, String.valueOf(huidigItem.isUitgeleend()));
}
stm.executeUpdate();
stm.close();
} catch (SQLException e) {
e.printStackTrace();
}
Or do I need to include the executeUpdate()
in the loop? And the PreparedStatement
? Or do I need to do an executeBatch()
?