瀹為檯涓婏紝榪欎釜閿欒鐨勫師鍥狅紝涓昏榪樻槸浠g爜闂寮曡搗鐨勩偮?br />
ORA-01000:聽maximum聽open聽cursors聽exceeded錛岃〃紺哄凡緇忚揪鍒頒竴涓繘紼嬫墦寮鐨勬渶澶ф父鏍囨暟銆?
聽聽 榪欐牱鐨勯敊璇緢瀹規槗鍑虹幇鍦↗ava浠g爜涓殑涓昏鍘熷洜鏄細Java浠g爜鍦ㄦ墽
琛宑onn.createStatement()鍜宑onn.prepareStatement()鐨勬椂鍊欙紝瀹為檯涓婇兘鏄浉褰撲笌鍦ㄦ暟鎹簱涓墦寮浜嗕竴涓?
cursor銆傚挨鍏舵槸錛屽鏋滀綘鐨刢reateStatement鍜宲repareStatement鏄湪涓涓驚鐜噷闈㈢殑璇濓紝灝變細闈炲父瀹規槗鍑虹幇榪欎釜闂銆傚洜
涓烘父鏍囦竴鐩村湪涓嶅仠鐨勬墦寮錛岃屼笖娌℃湁鍏抽棴銆?/span>
涓鑸潵璇達紝鍦ㄥ啓Java浠g爜鐨勬椂鍊欙紝createStatement鍜宲repareStatement閮藉簲璇ヨ鏀懼湪寰幆澶栭潰錛岃屼笖浣跨敤浜嗚繖浜?
Statment鍚庯紝鍙婃椂鍏抽棴銆傛渶濂芥槸鍦ㄦ墽琛屼簡涓嬈xecuteQuery銆乪xecuteUpdate絳変箣鍚庯紝濡傛灉涓嶉渶瑕佷嬌鐢ㄧ粨鏋滈泦
錛圧esultSet錛夌殑鏁版嵁錛屽氨椹笂灝哠tatment鍏抽棴銆偮?br />
瀵逛簬鍑虹幇ORA-01000閿欒榪欑鎯呭喌錛屽崟綰殑鍔犲ぇopen_cursors騫朵笉鏄ソ鍔炴硶錛岄偅鍙槸娌繪爣涓嶆不鏈傚疄闄呬笂錛屼唬鐮佷腑鐨勯殣鎮e茍娌℃湁瑙i櫎銆偮?br />
鑰屼笖錛岀粷澶ч儴鍒嗘儏鍐典笅錛宱pen_cursors鍙渶瑕佽緗竴涓瘮杈冨皬鐨勫鹼紝灝辮凍澶熶嬌鐢ㄤ簡錛岄櫎闈炴湁闈炲父鐗瑰埆鐨勮姹傘?
oracle聽9i聽榛樿鐨刼pen_cursors=300聽聽
涓銆佺湅鏈夐棶棰樼殑浠g爜
聽1聽import聽java.sql.Connection;
聽2聽import聽java.sql.DriverManager;
聽3聽import聽java.sql.SQLException;
聽4聽import聽java.sql.Statement;
聽5聽
聽6聽public聽class聽Test聽{
聽7聽聽聽public聽Connection聽getConnection()聽{
聽8聽聽聽聽聽String聽url聽=聽"jdbc:oracle:thin:@localhost:1521:ora9i";
聽9聽聽聽聽聽String聽user聽=聽"scott";
10聽聽聽聽聽String聽password聽=聽"tiger";
11聽聽聽聽聽Connection聽con聽=聽null;
12聽聽聽聽聽try聽{
13聽聽聽聽聽聽聽Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
14聽聽聽聽聽聽聽con聽=聽DriverManager.getConnection(url,聽user,聽password);
15聽聽聽聽聽}聽catch聽(Exception聽e)聽{
16聽聽聽聽聽聽聽e.printStackTrace();
17聽聽聽聽聽}
18聽聽聽聽聽return聽con;
19聽聽聽}
20聽
21聽聽聽public聽static聽void聽main(String[]聽args)聽throws聽SQLException聽{
22聽聽聽聽聽long聽a聽=聽13819100000L;
23聽聽聽聽聽long聽b聽=聽13819100600L;聽//聽闂鐐?/span>
24聽聽聽聽聽Connection聽con聽=聽null;
25聽聽聽聽聽Statement聽stmt聽=聽null;
26聽聽聽聽聽Test聽insert聽=聽new聽Test();
27聽聽聽聽聽try聽{
28聽聽聽聽聽聽聽con聽=聽insert.getConnection();
29聽聽聽聽聽聽聽for聽(long聽c聽=聽a;聽c聽<=聽b;聽c++)聽{
30聽聽聽聽聽聽聽聽聽String聽sql聽=聽"insert聽into聽telepnum聽values("聽+聽c聽+聽")";
31聽聽聽聽聽聽聽聽聽stmt聽=聽con.createStatement();聽//聽榪欓噷鏄棶棰樼殑鎵鍦?/span>
32聽聽聽聽聽聽聽聽聽stmt.executeUpdate(sql);
33聽聽聽聽聽聽聽}
34聽聽聽聽聽聽聽System.out.println("OK");
35聽聽聽聽聽}聽catch聽(Exception聽e)聽{
36聽聽聽聽聽聽聽e.printStackTrace();
37聽聽聽聽聽}聽finally聽{
38聽聽聽聽聽聽聽if聽(con聽!=聽null)聽{
39聽聽聽聽聽聽聽聽聽con.close();
40聽聽聽聽聽聽聽}
41聽聽聽聽聽}
42聽聽聽}
43聽}
浜屻佸垎鏋?/span>
鍦ㄥ驚鐜噷闈㈡瘡嬈¢兘
stmt = con.createStatement();
鑰屾病鏈夐噴鏀撅紝榪欐牱姣忎釜閮藉崰鐢ㄤ簡涓涓湇鍔″櫒鐨勬父鏍囪祫婧愶紝鏈鍚庨犳垚澶辮觸
涓夈佽В鍐蟲柟妗?/span>
1銆佸鍔犲叧闂鍙?
聽
1聽聽聽con聽=聽insert.getConnection();
2聽聽聽聽聽聽聽for聽(long聽c聽=聽a;聽c聽<=聽b;聽c++)聽{
3聽聽聽聽聽聽聽聽聽String聽sql聽=聽"insert聽into聽telepnum聽values("聽+聽c聽+聽")";
4聽聽聽聽聽聽聽聽聽stmt聽=聽con.createStatement();聽//聽榪欓噷鏄棶棰樼殑鎵鍦?/span>
5聽聽聽聽聽聽聽聽聽stmt.executeUpdate(sql);
6聽聽聽聽聽聽聽聽聽stmt.close();聽//聽鐢ㄥ畬浜嗗氨鍏抽棴濂戒簡
7聽聽聽聽聽聽聽}
2銆佸皢榪欏彞璇濈Щ鍔ㄥ埌寰幆澶栭潰錛屾帹鑽愮敤榪欎釜
1聽con聽=聽insert.getConnection();
2聽聽聽聽聽聽聽stmt聽=聽con.createStatement();聽//聽縐誨姩鍒拌繖閲岋紝Statemet鏄彲浠ラ噸鐢ㄧ殑
3聽聽聽聽聽聽聽for聽(long聽c聽=聽a;聽c聽<=聽b;聽c++)聽{
4聽聽聽聽聽聽聽聽聽String聽sql聽=聽"insert聽into聽telepnum聽values("聽+聽c聽+聽")";
5聽聽聽聽聽聽聽聽聽stmt.executeUpdate(sql);
6聽聽聽聽聽聽聽}
7聽聽聽聽聽聽聽stmt.close();聽//聽鐢ㄥ畬浜嗗氨鍏抽棴濂戒簡
3銆佹敼瑁呮垚鎵歸噺鏇存柊
1聽con聽=聽insert.getConnection();
2聽聽聽聽聽聽聽con.setAutoCommit(false);
3聽聽聽聽聽聽聽stmt聽=聽con.createStatement();聽//聽縐誨姩鍒拌繖閲岋紝Statemet鏄彲浠ラ噸鐢ㄧ殑
4聽聽聽聽聽聽聽for聽(long聽c聽=聽a;聽c聽<=聽b;聽c++)聽{
5聽聽聽聽聽聽聽聽聽String聽sql聽=聽"insert聽into聽telepnum聽values("聽+聽c聽+聽")";
6聽聽聽聽聽聽聽聽聽stmt.addBatch(sql);
7聽聽聽聽聽聽聽}
8聽聽聽聽聽聽聽stmt.executeBatch();
9聽聽聽聽聽聽聽con.commit();
鍥涖佹葷粨
聽聽聽 閴翠簬涓婇潰鐨勯棶棰橈紝鍦ㄥ仛鍩虹被鐨勬椂鍊欙紝鍦ㄥ鏁版嵁榪涜DML鎿嶄綔鐨勬椂鍊欙紝灝介噺涓嶈璁╁熀綾昏繑鍥濻tatement,鑰屽簲璇ュ湪鍩虹被鐩存帴榪涜鍏抽棴銆傚湪鍋氭煡璇㈢殑鏃跺欙紝鍙?
浠ユ妸statement鐣欑粰紼嬪簭鍛樿嚜宸辮繘琛屾墜鍔ㄥ叧闂紝鍏抽棴鐨勬柟娉曚負錛氱粰ResultSet涓涓柟娉曞彲浠ュ緱鍒癝tatement錛岀劧鍚庡啀鍏抽棴
Statement銆備釜浜鴻涓鴻繖縐嶆柟娉曟槸姣旇緝濡ュ綋鐨勩?br />
]]>