Maximum number of cursors exceeded in the Java Code Toolbox

Source: Internet
Author: User

1. This error occurs when Java is heavily written to Oracle. After this mistake, also touches oneself to have a deep understanding of Java Preparestatement and other objects, and database connection and release.

2. Cause: Database write operations are often performed in a For loop.

3. Code:

Case: When I was importing Excel into an Oracle database, I didn't understand it because I searched the online code. When you traverse every row of data in Excel, you execute the

pre = con.preparestatement (SQL). The Pre.close () is not executed until the 5000 rows of data in Excel have been traversed, and the result is an error, appearing

Cursor error exceeded! It was later corrected to execute pre.executequery () within the For loop, followed by immediate execution of Pre.close ();

A pre-empty judgment statement). Once corrected, 5,000 data was imported smoothly.

classmycode{connection con=NULL; PreparedStatement Pre=NULL; ResultSet result=NULL;voidReadexcel () { for(...)  for(...) Update ();}voidUpdate () {String SQL= "Update Mytabe set a=?" where id=? "; Pre=conn.preparestatement (SQL); Pre.setstring (1, A); Pre.setlong (2, 123);    Pre.executeupdate (); //Error}Static voidMain (string[] args) {conndb () initdbobj () Readexcel ()}}

The correct update () function should be as follows:

//Correct codevoidUpdate () {String SQL= "Update Mytabe set a=?" where id=? "; Pre=conn.preparestatement (SQL); Pre.setstring (1, A); Pre.setlong (2, 123);    Pre.executeupdate (); //Focus    if(Pre! =NULL) {pre.close (); }}//The pre object must be closed immediately after use, do not put it to the end and close together with Conn. //Otherwise, each time the pre is set, a cursor is requested, and the general cursor is only 300//you'll get an error soon. 

Maximum number of cursors exceeded in the Java Code Toolbox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.