Java Statement. Addbath() method: add batch statement
•
Java
addBatch(String sql)
Typical application
public void bathInsert(){ Connection conn=getCon(); //省略部分代码 String sql1="insert into tb_users(name)values('aaa')"; //添加数据 String sql2="insert into tb_users(name)values('bbb')"; String sql3="insert into tb_users(name)values('ccc')"; Statement stmt; try{ stmt=conn.createStatement(); //获取Statement对象 stmt.addBatch(sql1); //添加sql语句 stmt.addBatch(sql2); stmt.addBatch(sql3); stmt.executeBatch(); //批量执行 stmt.close(); }catch(sqlException e){ e.printStackTrace(); } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码