📄 batchedpreparedstatement.java
字号:
/* * BatchedPreparedStatement.java * * Created on June 12, 2005, 12:32 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package ch04;import java.util.*;import java.sql.*;import javax.sql.*;import ch03.*;import common.*;/** * * @author kevin */public class BatchedPreparedStatement { /** Creates a new instance of BatchedPreparedStatement */ public BatchedPreparedStatement() { } public static void main(String[] args){ Connection conn = null; PreparedStatement pstmt = null; try{ conn = ConnectionFactory.getConnectionFactory().getConnection(); String insert = "insert into simple_tbl (id, name) values (?, ?)"; pstmt = conn.prepareStatement(insert); conn.setAutoCommit(false); pstmt.setInt(1, 100); pstmt.setString(2, "kevin100"); pstmt.addBatch(); pstmt.setInt(1, 200); pstmt.setString(2, "kevin200"); pstmt.addBatch(); int[] results = pstmt.executeBatch(); for(int i = 0; i < results.length; i++){ System.out.println(results[i]); } conn.commit(); }catch(SQLException e){ try{ conn.rollback(); }catch(Exception ie){} ExportSQLInfo.showSQLException(e); }catch(Exception e){ e.printStackTrace(); }finally{ DBUtils.close(pstmt, conn); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -