使用JDBC批处理操作Oracle数据库:
1.使用addBatch方法添加DML语句;
2.使用executeBatch方法提交批处理语句。

实例:
TestBatch.java:
  1. import java.sql.*;   
  2.   
  3. public class TestBatch {   
  4.   
  5.     public static void main(String[] args) {   
  6.            
  7.         Connection conn = null;   
  8.         PreparedStatement pstmt = null;   
  9.            
  10.         try {   
  11.             Class.forName("oracle.jdbc.driver.OracleDriver");   
  12.             conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:mgc","system","admin");   
  13.             String sql = "Insert INTO member(id,name) VALUES(?,?)";   
  14.             pstmt = conn.prepareStatement(sql);   
  15.             pstmt.setInt(112);   
  16.             pstmt.setString(2"n12");   
  17.             pstmt.addBatch();   
  18.             pstmt.setInt(113);   
  19.             pstmt.setString(2"n13");   
  20.             pstmt.addBatch();   
  21.             pstmt.setInt(114);   
  22.             pstmt.setString(2"n14");   
  23.             pstmt.addBatch();   
  24.             pstmt.executeBatch();   
  25.         } catch (ClassNotFoundException e) {   
  26.             e.printStackTrace();   
  27.         } catch (SQLException e) {   
  28.             e.printStackTrace();   
  29.         } finally {   
  30.             try {   
  31.                 if (pstmt != null) {   
  32.                     pstmt.close();   
  33.                     pstmt = null;   
  34.                 }   
  35.                 if (conn != null) {   
  36.                     conn.close();   
  37.                     conn = null;   
  38.                 }   
  39.             } catch (SQLException e) {   
  40.                 e.printStackTrace();   
  41.             }   
  42.         }   
  43.     }   
  44.   }