the below method is to insert records to sqlite database table, and i know that this method wil be called numerous times from inside loops.
my question is, is the code below the optimum way to insert values into DB table?or there could be a better approach as the time and performance matter.
kindly please advice.
code:
public void insertValues(String name, int age, String address, String gender) throws SQLException, ClassNotFoundException {
Connection conn = getConnection();
PreparedStatement ps = conn.prepareStatement("insert into "+TABLE_NAME+" ("+COL_1+", "+COL_2+", "+COL_3+", "+COL_4+") values (?, ?, ?, ?)");
ps.setString(1, name);
ps.setLong(2, age);
ps.setString(3, address);
ps.setString(4, gender);
ps.addBatch();
ps.executeBatch();
ps.close();
conn.close();
}
Aucun commentaire:
Enregistrer un commentaire