batchedpreparedstatement.java
来自「这是一本描述JDBC数据库的书籍」· Java 代码 · 共 61 行
JAVA
61 行
/* * 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 + =
减小字号Ctrl + -
显示快捷键?