gpt4 book ai didi

java - 下面的代码只能将附加文件中 20000 个数字中的 226 个数据插入到 TEMPTABLE 的数字列中

转载 作者:行者123 更新时间:2023-12-01 09:29:04 25 4
gpt4 key购买 nike

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

[   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,它们各自使用数据库上的游标资源。

您可以在 executeUpdate() 之后添加 pre2.close() - 这将解决当前的问题。但它会非常慢并且需要大量资源 - 正如其他地方所指出的,您应该研究批处理和绑定(bind)变量。

关于java - 下面的代码只能将附加文件中 20000 个数字中的 226 个数据插入到 TEMPTABLE 的数字列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39600821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com