java


The code below can only insert 226 data OUT of the 20000 numbers from attached file into number column of the TEMPTABLE


The code below can only insert 226 out of 20000 numbers from a supplied file into a number column of the TEMPTABLE, and then throws
[ 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 ]
Here is the code:
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);
}
Please can anyone help me fix this?
You aren't closing your PreparedStatements, and they each use cursor resources on your database.
You could add a pre2.close() after the executeUpdate() - that would fix the immediate issue. But it will be very slow and resource intensive - as noted elsewhere, you should look into batching and bind variables.
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
String sql1 ="insert into TEMPTABLE(numbers)values(?)";
pre2=conn.prepareStatement(sql1);
String line;
while ((line=br.readLine())!=null) {
String[] value=line.split(",");
pre2.setString(1,value[0]); //if its number use setInt
pre2.addBatch();
}
pre2.executeBatch();
pre2.close(0);
br.close();// closing the buffered reader
conn.close(); //closing database connection to free system resources
}
}
catch(ClassNotFoundException | SQLException | IOException e){
JOptionPane.showMessageDialog(null,e);}
try adding batch.this will speed up your performance as well

Related Links

Set multiple listeners to one method
why one class of same package can't access another?
cannot find symbol : class NumberTools
Java apache POI java.lang.IllegalArgumentException: Position 21504 past the end of the file
Selenium Automatically Closes Chrome Console (attached or window)
How to check values in collection for uniques by some criteria using Java 8
java.util.concurrent.locks.Condition awaitUninterruptibly()
what is the purpose of this tmp variable in android sample bluetooth chat application
ASM. Clone JumpInsnNode correctly
codenameone is there a simpler/nicer way to call a Web Service?
Spark job-server
Add data from file into ArrayList and sorting
Android dev studio Making a notification have multiple lines of text display and close on touch
How to persist Joda Date to sql database?
Java Keypressed event on netbeans gui does not work?
Java FileOutputStream Windows/Linux

Categories

HOME
openmp
google-api-php-client
vmware
relay
read-eval-print-loop
cvs
paw-app
echarts
medical
dacpac
vifm
quickbooks
task
messages
fortumo
designer
clearcase-ucm
ghc
evopdf
code-review
excel-vba-mac
samoa
lldb
jasonette
mps
chromium-embedded
tibco-mdm
rundeck
microsoft-sync-framework
brunch
procdump
binary-data
pdb
fog
perlin-noise
swisscomdev
unspecified
ws-security
btrace
wptoolkit
appcompat
upstart
atomicity
zip4j
winscp-net
tropo
migradoc
yt-project
time-and-attendance
jquery-filter
url-pattern
nxt
markojs
bgp
revolution-r
wapiti
freedesktop.org
metaclass
browser-bugs
appfabric-cache
processmodel
p2
lustre
website-monitoring
codeigniter-url
applescript-objc
html-helper
code-access-security
bitcoinj
xojo
castle
google-reader
yorick
didselectrowatindexpath
mcts
mysqltuner
runtime.exec
ember-app-kit
sabredav
tinn-r
dice
hosts-file
parametric-equations
osql
f#-powerpack
remember-me
virtual-functions
sustainable-pace
wsdl.exe

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App