下面的代码只能将所提供文件中的20000个数字中的226个插入TEMPTABLE的number列,然后抛出

[   java.sql.SQL.Exception:ORA-00604: error occurred at recursive SQL level
1ORA-01000: maximum open cursors exceeded
ora-00604:  error occurred at recursive SQL level 1
ORA-01000: maximum open cursors exceeded
ORA-01000: maximum open cursors exceeded   ]


这是代码:

private void ButtonloadActionPerformed(java.awt.event.ActionEvent evt) {
      PreparedStatement pre2;
      //loading the database driver and initiating a connection to it
      //all statement in a try and catch block
      try {
          String driverName="oracle.jdbc.driver.OracleDriver";
                Class.forName(driverName);
                String url ="jdbc:oracle:thin:@"+serverName+":"+serverport+":"+sid;
                conn =DriverManager.getConnection(url,username,password);

// uploading the content on the csv file in the path into the TempTable in the DB
          try (BufferedReader br = new BufferedReader(new FileReader(path))) {
              String line;
               while ((line=br.readLine())!=null) {
                  String[] value=line.split(",");
                  String sql1 ="insert into TEMPTABLE(numbers)values('"+(value[0])+"')";
                  pre2=conn.prepareStatement(sql1);
                  pre2.executeUpdate();
              }
              br.close();  // closing the buffered reader
              conn.close();   //closing database connection to free system resources
          }
     }
     catch(ClassNotFoundException | SQLException | IOException e) {
         JOptionPane.showMessageDialog(null,e);
     }


请谁能帮我解决这个问题?

最佳答案

您没有关闭PreparedStatements,它们每个都使用数据库上的游标资源。

您可以在pre2.close()之后添加executeUpdate()-这样可以解决当前问题。但这将非常缓慢且占用大量资源-如其他地方所述,您应该研究批处理和绑定变量。

07-27 23:44