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