?? batchupdates.java
字號(hào):
/** * A simple sample to demonstrate Batch Updates. * Please use jdk1.2 or later version */import java.sql.*;public class BatchUpdates{ public static void main(String[] args) { Connection conn = null; Statement stmt = null; PreparedStatement pstmt = null; ResultSet rset = null; int i = 0; try { DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); String url = "jdbc:oracle:oci8:@"; try { String url1 = System.getProperty("JDBC_URL"); if (url1 != null) url = url1; } catch (Exception e) { // If there is any security exception, ignore it // and use the default } // Connect to the database conn = DriverManager.getConnection (url, "hr", "hr"); stmt = conn.createStatement(); try { stmt.execute( "create table mytest_table (col1 number, col2 varchar2(20))"); } catch (Exception e1) {} // // Insert in a batch. // pstmt = conn.prepareStatement("insert into mytest_table values (?, ?)"); pstmt.setInt(1, 1); pstmt.setString(2, "row 1"); pstmt.addBatch(); pstmt.setInt(1, 2); pstmt.setString(2, "row 2"); pstmt.addBatch(); pstmt.executeBatch(); // // Select and print results. // rset = stmt.executeQuery("select * from mytest_table"); while (rset.next()) { System.out.println(rset.getInt(1) + ", " + rset.getString(2)); } } catch (Exception e) { e.printStackTrace(); } finally { if (stmt != null) { try { stmt.execute("drop table mytest_table"); } catch (Exception e) {} try { stmt.close(); } catch (Exception e) {} } if (pstmt != null) { try { pstmt.close(); } catch (Exception e) {} } if (conn != null) { try { conn.close(); } catch (Exception e) {} } } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -