Home > Database > Mysql Tutorial > 批量操作数据库,提高数据库效率

批量操作数据库,提高数据库效率

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:11:11
Original
1813 people have browsed it

例如有一个ArrayList al = new ArrayList(); al中存放了若干个user对象: 在执行前面的得到数据库连接之后,执行如下操作: Statement st = ct.createStatement(); for(int i=0;ial.size();i){ User u=(User)al.get(i); sm.addBatch(insert into user values

例如有一个ArrayList  al = new ArrayList();

al中存放了若干个user对象:

在执行前面的得到数据库连接之后,执行如下操作:

Statement st = ct.createStatement();

for(int i=0;i

User u=(User)al.get(i);

sm.addBatch("insert into user values('"+u.getUsername+"','"+u.getPasswd()+"','"+u.getGrade()+"')");

}

sm.executeBatch();

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template