日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

利用JDBC中處理批量更新oracle數(shù)據(jù)

 明郎月 2007-04-19
JDBC課的時候,聽到一節(jié)是講在利用JDBC中處理批量更新oracle數(shù)據(jù)時候的特性,讓我很為JDBC的特性感的興奮,利用這個特性可以在批量更新數(shù)據(jù)的時候不同往常一樣每次都需要傳送完成的SQL語句到數(shù)據(jù)庫中。其中示范代碼如下:

1 import java.sql.*;
2
3 public class BatchUpdates
4 {
5   public static void main(String[] args)
6   {
7     Connection          conn = null;
8     Statement           stmt = null;
9 PreparedStatement pstmt = null;
10     ResultSet           rset = null;
11     int                 i = 0;
12
13     try
14     {
15       DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
16
17       String url = "jdbc:oracle:oci8:@";
18       try {
19       //檢查是否配置JDBC環(huán)境變量
20         String url1 = System.getProperty("JDBC_URL");
21         if (url1 != null)
22           url = url1;
23       } catch (Exception e) {
24         //如果是在集成開發(fā)環(huán)境導(dǎo)入了JDBC的話可以注釋這句
25       }
26
27       // 連接到數(shù)據(jù)庫用 scott
28       conn = DriverManager.getConnection (url, "scott", "tiger");
29
30       stmt = conn.createStatement();
31       try { stmt.execute(
32             "create table mytest_table (col1 number, col2 varchar2(20))");
33       } catch (Exception e1) {}
34
35       //
36       // 批量插入新值.
37       //
38       pstmt = conn.prepareStatement("insert into mytest_table values (?, ?)");
39
40       pstmt.setInt(1, 1);
41       pstmt.setString(2, "row 1");
42       pstmt.addBatch();
43
44       pstmt.setInt(1, 2);
45       pstmt.setString(2, "row 2");
46       pstmt.addBatch();
47
48       pstmt.executeBatch();
49
50       //
51       // 查詢 輸出結(jié)構(gòu)集
52       //
53       rset = stmt.executeQuery("select * from mytest_table");
54       while (rset.next())
55       {
56         System.out.println(rset.getInt(1) + ", " + rset.getString(2));
57       }
58     }
59     catch (Exception e)
60     {
61       e.printStackTrace();
62     }
63     finally
64     {
65       if (stmt != null)
66       {
67     try { stmt.execute("drop table mytest_table"); } catch (Exception e) {}
68         try { stmt.close(); } catch (Exception e) {}
69       }
70       if (pstmt != null)
71       {
72         try { pstmt.close(); } catch (Exception e) {}
73       }
74       if (conn != null)
75       {
76         try { conn.close(); } catch (Exception e) {}
77       }
78     }
79   }
80 }

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多