java - H2: executeBatch doesn't work -
i have following code
string query = "insert student (age,name) values (?,?)"; conn.setautocommit(true); ps = conn.preparestatement(query); (student student:list) { ps.setint(1, student.getage()); ps.setstring(2, student.getname()); } int[]temp=ps.executebatch(); system.out.println("temp:"+temp.length);//returns 0
the code executed. no errors no exceptions. table student empty. use h2 1.3.176 in embedded mode. wrong?
you forgot add batch set of parameters:
string query = "insert student (age,name) values (?,?)"; conn.setautocommit(true); ps = conn.preparestatement(query); (student student:list) { ps.setint(1, student.getage()); ps.setstring(2, student.getname()); ps.addbatch(); // <-- } int[]temp=ps.executebatch(); system.out.println("temp:"+temp.length);
Comments
Post a Comment