if (!knowledge.isEmpty()) {
Iterator<Entry<String, String>> classnmValsItrKW = knowledge
.entrySet().iterator();
while (classnmValsItrKW.hasNext()) {
Entry<String, String> p1 = classnmValsItrKW.next();
String nm = p1.getKey();
String val = p1.getValue();
String query3 = "insert into namevalue(seqid, name, value) values("
+ seqId + ",'" + nm + "','" + val + "')";
//System.out.println("Insert query: " + query3);
st = connect.createStatement();
st.executeUpdate(query3);
}
}
"knowledge" is the hashtable where i have stored name value pairs which i want to insert into database. but for every iteration of while loop insert query is getting fired. which i think is inefficient. how do i insert multiple rows by firing insert query only once?
PreparedStatement#addBatchandStatement#executeBatch