本质来讲就是使用statement和prestatement的addbatch()方法
代码
开发语言:java,支持数据库:Mysql 5,系统架构:J2EE,操作系统:linux/Windows1. 引言 32. 系统的结构 32.1 系统概述 33. 功能模块设计说明 43.1 商品管理 43.1.1 添加商品功能模块 53.1.2 商品列表功能模块 83.1.3 商品关联功能模块 93.
import java.sql.*;
public class GetConnection{
public static void main(String[] args){
Access2Database adb=new Access2Database();
Connection conn=adb.getConn();
//transaction dealing
PreparedStatement pstam=null;
try{
conn.setAutoCommit(false);
String sql="insert into student(name,major,score) values(?,?,?);";
pstam=conn.prepareStatement(sql);
pstam.setString(1, "f");
pstam.setString(2,"History");
pstam.setInt(3, 67);
pstam.addBatch();
pstam.setString(1, "h");
pstam.setString(2, "Biology");
pstam.setInt(3, 85);
pstam.addBatch();
pstam.executeBatch();
conn.commit();
}catch(SQLException e){
try {
conn.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}finally{
try {
conn.setAutoCommit(true);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//release the resource of the program
try{
pstam.close();
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}










