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

Storing Objects of Class into an Array
How to start testing a RESTful web service using Java ? [duplicate]
kafka consumer to dynamically detect topics added
RMI Client/Sever - File Transfer
Usage of super in method declaration
How to save ID passed by activity (android) [closed]
Re-sizing an image which in Base64 format and converting to Base64 again in java
How to abstract a binary search that is not over a data structure?
ProgressDialog shows before 2nd TabBar fragment is opened
TCP Server & Client : IOException raised when Server respond to Client
string split pattern java
Looping user information
No use of nillable=“0” in SOAP Webservice
Executing batch files using process and runtime classes
JTable reseting to original state after minimize/maximize
SpringFramework and DBUnit integration test NoSuchBeanDefinitionException Java

Categories

HOME
multithreading
cplex
react-router
dxl
google-project-tango
callback
installshield
opengl-es-2.0
constraint-programming
rascal
mapserver
modelica
static-libraries
messages
fortumo
circuit
libtiff
connection-string
jqwidget
wkwebview
tapestry
semantic-analysis
intel-pin
lightswitch-2013
xquery-3.0
siesta-swift
karaf
caret
http-digest
suricata
event-driven
android-browser
objectlistview
az-application-insights
sas-visual-analytics
eclipse-scout
ibpy
reactive-cocoa-5
wptoolkit
upstart
togetherjs
boost-preprocessor
capacity
migradoc
trash
google-web-starter-kit
merge-conflict-resolution
sdf
php-internals
design-by-contract
oauth2client
teamcity-8.0
collapse
map-projections
mmc
iiviewdeckcontroller
clipperlib
inmobi
gwidgets
xc16
mdt
gulp-less
castle
mysql-error-1062
jsctypes
ruby-datamapper
tinn-r
trusted
automount
getmessage
buildr
subgurim-maps
invite
self-extracting
yui-datatable
asp.net-mvc-areas
web-application-design
nhibernate.search
preference
ext3
rescale
user-friendly
uimenucontroller

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