JDBC / cursors
I have a JAVA application in which I query an Oracle 8 DB using
SQL statements via a JDBC connection/driver
The following exception is being thrown
java.sql.SQLException: ORA-01000: maximum open cursors exceeded
can someone please explain WHY
As far as I am concerned the DB should handle each SQL query
independantly
If I've understood things - a CURSOR is a DB 'pointer' to memory
in which it can store a ResultSet
If the DB can't handle my SINGLE USER GUI app query rate then
what hope is there for multiple users when I get to full system
tests
null
Stefn Maric (guest) wrote:
: I have a JAVA application in which I query an Oracle 8 DB using
: SQL statements via a JDBC connection/driver
: The following exception is being thrown
: java.sql.SQLException: ORA-01000: maximum open cursors exceeded
: can someone please explain WHY
: As far as I am concerned the DB should handle each SQL query
: independantly
: If I've understood things - a CURSOR is a DB 'pointer' to
memory
: in which it can store a ResultSet
: If the DB can't handle my SINGLE USER GUI app query rate then
: what hope is there for multiple users when I get to full system
: tests
Hi,
the initialization parameter open_cursors determines the maximum
cursors PER USER, so this has nothing to do with single/muliple
users.
Maybe your program opens a large number of cursors (remember that
every SQL statement opens a cursor implicit) and/or the init.ora
parameter open_cursors is at its default, wich is not very high
(20 or 50 if I remember right). Check if you close all your
cursors, also check SQL in loops. You may also increase the
init.ora parameter open_cursors (restart the database after
this); a value of 200 is not too high (we have set it to 400 in
our current project)
peter
null
Similar Messages
-
Extracting data from a jdbc cursor
Hello,
I'm writing a program that trasfers data from access to oracle. I have the oracle insert statements in a seperate try catch block. If the record isn't written for whatever reason, I want to instert the record ID into a log table that tracks failed transactions.
I'm just using an ODBC/JDBC method for accessing the data in access. We didn't want the cost of buying a robust Access driver.
My question is the following statement produces an error
accessStatement.execute("Insert into Failed(Record_ID) values"+accessRs.getInt("Record_ID"));
The error is java.sql.sqlException: No data found
Please help
thanksYou could try this:
accessStatement.execute("Insert into Failed(Record_ID) values ("+accessRs.getInt("Record_ID"))+")"; // You forgot parentheses!
But better is when you don't declare a Statement, but a PreparedStatement:
PreparedStatement stmt=con.prepareStatement("INSERT INTO failed(record_id) VALUES (?)");
stmt.setInt(1,accessRs.getInt("Record_ID"));
stmt.executeUpdate();
This way your statement can be reused (faster and more memory-efficient!) -
How to Create a datatype for a storeprocedure which has got array ?
Hi All,
Please tell me how to create a datatype for a storeprocedure which has got an array structure ?
Thanks,
Sindhu.Hi Sindhu.
You would have to use a JDBC Cursor for this but it's possible only Output parameters, not Input parameters.
It's describle in a help link:
Defining an EXECUTE Statement http://help.sap.com/saphelp_nwpi711/helpdata/en/44/7b72b2fde93673e10000000a114a6b/frameset.htm
The following SQL data types are supported:
INTEGER, BIT, TINYINT, SMALLINT, BIGINT, FLOAT, REAL, DOUBLE, NUMERIC, DECIMAL, CHAR, VARCHAR, STRING, LONGVARCHAR, DATE, TIME, TIMESTAMP, BINARY, VARBINARY, LONGVARBINARY, BLOB (input and output), CLOB (input and output), CURSOR (output; only in connection with the Oracle JDBC driver)
I think you can execute your StoreProcedure many times depends of array occurs.
Regards.
Bruno. -
A wierd problem in a user exit in IT0030
hello,
In infotype 0030 we developed a new field. Then we developed a user-
exit which delimits a record after opening a new one (the info typy is
has time constraint=3).
When the user looks with the overview icon or the display icon it's
seems as if the first record is NOT delimited. Only if the user turns
back to the main menu and then returns to PA30 to the overview icon or
the display icon the first record is shown delimited.
It seems like some sort of a TRIVIAL progarmming issue (REFRESH or something of this sort).
But we can not put our fingers on it.
Please, help.
thank you.
zohar
p.s., I have screenshots but I do not know how to attach them to this posting.I think your problem is related to JDBC cursors being forward only. Once you call next (or whatever the call is to move the cursor forward), you can't get at values you've left behind. As the table needs to repaint, it is trying to access those values and throwing a fit.
Have a look on the Java Pro (magazine) web site. They did a CachedResultSet a little while ago that I think would solve your problem.
Good luck -
Hello all,
We have configured JDBC Sender Adapter which fetches around 10K records with poll interval 1hr from DB2 System .
It was working fine,suddenly it started throwing an exception in Adapter Monitoring :
Error during conversion of query result to XML: java.sql.SQLException: Cursor state not valid.
It is not fetching any records.
Without changing any configurations when we tried to fetch to around 1000 records it's working fine.
For 10K records same exception persists
What could be the reason ?How to resolve this issue?
regards
GangaPrasadHello Christophe ,
Trace in VA :::
Date : 05/09/2008
Time : 11:45:57:750
Message : Unexpected error converting database resultset to XML, reason: java.sql.SQLException: Cursor state not valid.
at java.lang.Throwable.<init>(Throwable.java:194)
at java.lang.Exception.<init>(Exception.java:41)
at java.sql.SQLException.<init>(SQLException.java:40)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:389)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:366)
at com.ibm.as400.access.AS400JDBCResultSet.getValue(AS400JDBCResultSet.java:3580)
at com.ibm.as400.access.AS400JDBCResultSet.getString(AS400JDBCResultSet.java:3223)
at sun.reflect.GeneratedMethodAccessor459222074.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:309)
at com.sap.aii.adapter.jdbc.sql.jdbctrace.TraceInvocationHandler.invoke(TraceInvocationHandler.java:45)
at com.sap.aii.adapter.jdbc.sql.jdbctrace.$Proxy254.getString(Unknown Source)
at com.sap.aii.adapter.jdbc.JDBC2XI.convert2XML(JDBC2XI.java:954)
at com.sap.aii.adapter.jdbc.JDBC2XI.invoke(JDBC2XI.java:492)
at com.sap.aii.af.service.scheduler.JobBroker$Worker.run(JobBroker.java:475)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:99)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:119)
Severity : Error
Category : /Applications/ExchangeInfrastructure/AdapterFramework/Services/ADAPTER/ADMIN/JDBC
Location : com.sap.aii.adapter.jdbc.JDBC2XI.convert2XML(ResultSet, ResultSetMetaData)
Application :
Thread : XI JDBC2XI[JDBC_SND_DB2_VehicleReceiving/DB2PRD00/]_170
Datasource : 12428950:/usr/sap/PXI/DVEBMGS01/j2ee/cluster/server0/log/applications/com.sap.xi/xi.log
Message ID : 00145E742794005E0014980B000000BE00044CC763766C4F
Source Name : /Applications/ExchangeInfrastructure/AdapterFramework/Services/ADAPTER/ADMIN/JDBC
Argument Objs : java.sql.SQLException: Cursor state not valid.
at java.lang.Throwable.<init>(Throwable.java:194)
at java.lang.Exception.<init>(Exception.java:41)
at java.sql.SQLException.<init>(SQLException.java:40)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:389)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:366)
at com.ibm.as400.access.AS400JDBCResultSet.getValue(AS400JDBCResultSet.java:3580)
at com.ibm.as400.access.AS400JDBCResultSet.getString(AS400JDBCResultSet.java:3223)
at sun.reflect.GeneratedMethodAccessor459222074.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:309)
at com.sap.aii.adapter.jdbc.sql.jdbctrace.TraceInvocationHandler.invoke(TraceInvocationHandler.java:45)
at com.sap.aii.adapter.jdbc.sql.jdbctrace.$Proxy254.getString(Unknown Source)
at com.sap.aii.adapter.jdbc.JDBC2XI.convert2XML(JDBC2XI.java:954)
at com.sap.aii.adapter.jdbc.JDBC2XI.invoke(JDBC2XI.java:492)
at com.sap.aii.af.service.scheduler.JobBroker$Worker.run(JobBroker.java:475)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:99)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:119)
Arguments : java.sql.SQLException: Cursor state not valid.
at java.lang.Throwable.<init>(Throwable.java:194)
at java.lang.Exception.<init>(Exception.java:41)
at java.sql.SQLException.<init>(SQLException.java:40)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:389)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:366)
at com.ibm.as400.access.AS400JDBCResultSet.getValue(AS400JDBCResultSet.java:3580)
at com.ibm.as400.access.AS400JDBCResultSet.getString(AS400JDBCResultSet.java:3223)
at sun.reflect.GeneratedMethodAccessor459222074.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:309)
at com.sap.aii.adapter.jdbc.sql.jdbctrace.TraceInvocationHandler.invoke(TraceInvocationHandler.java:45)
at com.sap.aii.adapter.jdbc.sql.jdbctrace.$Proxy254.getString(Unknown Source)
at com.sap.aii.adapter.jdbc.JDBC2XI.convert2XML(JDBC2XI.java:954)
at com.sap.aii.adapter.jdbc.JDBC2XI.invoke(JDBC2XI.java:492)
at com.sap.aii.af.service.scheduler.JobBroker$Worker.run(JobBroker.java:475)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:99)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:119)
Dsr Component :
Dsr Transaction : d1f629d01d9b11dd984200145e742794
Dsr User :
Indent : 0
Level : 0
Message Code :
Message Type : 1
Relatives : com.sap.aii.adapter.jdbc.JDBC2XI
Resource Bundlename :
Session : 0
Source : /Applications/ExchangeInfrastructure/AdapterFramework/Services/ADAPTER/ADMIN/JDBC
ThreadObject : XI JDBC2XI[JDBC_SND_DB2_VehicleReceiving/DB2PRD00/]_170
Transaction : SAP J2EE Engine JTA Transaction : [0ffffffbdffffffa6ffffff960086]
User : J2EE_GUEST
Regards
Ganga Prasad -
Help - JDBC MS SQL Server and Cursors Error
Hello,
Please help. I am using weblogic 8.1 and MS SQL Server 2000. Using JDBC. I have am calling a stored procedure which outputs a CURSOR. I haveing problems specifying the right java.sql.Type for this. I tried java.sql.Type.OTHER but it fails. The code is as follows
Connection conn = null;
CallableStatement stmt = null;
String sqlProc = "{ call GetDocumentDetails(?,?) }";
try {
conn = this.getConnection();
stmt = conn.prepareCall(sqlProc);
stmt.setInt(1, docId);
stmt.registerOutParameter(2,Types.OTHER);
stmt.execute();
ResultSet rs = (ResultSet) stmt.getObject(2);
while(rs.next()) {
The exception that I get is
java.sql.SQLException: [BEA][SQLServer JDBC Driver]The specified SQL type is not supported by this driver.
at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
PLEASE HELP.
Thanks in advance
GMhi llturro,
Thanks for answering my question. I have tried out what you suggested, but I still can't fix my problem. The following are the messages that display when I try to run my servlet. It seems that the DataSource, Connection and Statement are ok, however when it comes to the ResultSet the error message appear. What's wrong with my ResultSet coding ?
ResultSet rs = stat.executeQuery("SELECT ISBN FROM BOOKSINFO WHERE ISBN='"+primarykey+"'");
setEntityContext Method
Find by primary key
DataSource OK
Connection OK
Primary Key = 013-00-675721-9
Statement OK
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: Unknown Exception/Error thrown by EJB method.; nested exception is:
java.lang.NullPointerException
java.rmi.RemoteException: Unknown Exception/Error thrown by EJB method.; nested exception is:
java.lang.NullPointerException
java.lang.NullPointerException
<<no stack trace available>> -
Hi,
Could it be possible that even if all ResultSet and Statement objects are closed (in finally blocks so that the close() statements are guaranteed to be executed), one can still get ORA 1000 or max open cursors exceeded? Is there a bug in JDBC that makes the cursors linger even though they have been closed by the program? I ask this because a colleague of mine insists that there is such a JDBC bug and that the only workaround is to close the Connection object. He also claims that the "bug" is fixed in Oracle 9i. We are using Oracle 8.1.7.0.0 on HP-UX 11.0 with java 1.3.1 Any info greatly appreciated. Thanks.
VasuMax cursors open, is the problem encountered because of the database limitation of opening of new sessions. A new database session is created whenever a Statement/PreparedStatament is opened.
Make sure to close, Statement/PreparedStatement after its usage, as you have done in finally. This will ensure that it wont exceed the maximum open cursor limit.
I think this is the only cause for the baove problem and can be avoided.
Hope this helps
Ravi -
Using REF CURSOR from JDBC?
How do I use a REF CURSOR OUT parameter present in a Stored Procedure from my JDBC program?
here is an example, calling a packaged function. 1st param is delared as IN OUT REF CURSOR.
CallableStatement cs = conn.prepareCall("{? = call myPackage.myFunc(?,?)}");
cs.registerOutParameter (1, OracleTypes.INTEGER);
cs.registerOutParameter (2, OracleTypes.CURSOR);
cs.setInt(3,mInt.intValue());
boolean boolValue = cs.execute();
ResultSet cursor = ((OracleCallableStatement)cs).getCursor (2);
i hope this helps.
null -
Stored procedure call with REF CURSOR from JDBC
How can I call a SP with a REF CURSOR OUT parameter from JDBC?
This is a breeze.
CallableStatement oraCall = oraConn.prepareCall("BEGIN PKG_SOMETHING.RETURNS_A_SP(?);END;");
oraCall.registerOutParameter(1,oracle.jdbc.driver.OracleTypes.CURSOR);
oraCall.execute();
ResultSet rsServList = (ResultSet) oraCall.getObject(1);
... use ResultSet ...
rsServList.close();
oraCall.close();
slag -
SQL Server 2000 and JDBC,Registering cursor as OUT param
hi
I am using JDK1.4,SQL Server 2000 and Microsoft's JDBC driver.
I am stuck in accessing cursors.
The SP i wrote is
USE pubs
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'spSelectEmployees' and type = 'P')
DROP PROCEDURE spSelectEmployees
GO
CREATE PROCEDURE spSelectEmployees @emp_cursor CURSOR VARYING OUTPUT
AS
SET @emp_cursor = CURSOR
FORWARD_ONLY STATIC FOR
SELECT *
FROM employee
OPEN @emp_cursor
GO
The problem I face is that when i register the output param in java code,what datatype do I specify..code is written below.
calStmt = conn.prepareCall("{CALL pubs.dbo.spSelectEmployees(?)}", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
calStmt.registerOutParameter(1,Types.?????);-->What goes here???
java.sql.Types does not give any datatype for cursor or object.Any one knows if there is an extended type given by Microsoft Driver??I am using JDK1.4,SQL Server 2000 and Microsoft's JDBC driver. Premably for 2000. Numerous posts here suggests that driver has problems. The jTDS driver would be a better choice.
java.sql.Types does not give any datatype for cursor or object.Any one knows if there is an extended type given by Microsoft Driver??You are correct that it would require a driver specific type. I have no idea what it is.
Why don't you modify the proc to return a result set. -
Problem using REF CURSOR in JDBC
i have several stored procedures and functions that return REF CURSOR object as output. however, i'm noticing that if
no rows are returned within the cursor, the JDBC driver is throwing a "No more data to read from socket" exception.
i'm using the Oracle Thin JDBC driver v8.1.6 for JDK 1.2.
any help is appreciated.
thanks,
gary
nullI am not able to reproduce the problem. Could you post a testcase so that we can follow it up?
Thanks. -
Db2 - bea jdbc type 4 driver error - cursor not in a prepared state
Hi
I am getting this error from BEA DB2 Driver in weblogic console.
java.sql.SQLException: [BEA][DB2 JDBC Driver][DB2]CURSOR C02 NOT IN A
PREPARED STATE
This problem occurs frequently almost everyday.
When this error happens we clear the statement cache by logging in to the weblogic console (which clears the cache of prepared and callable statements maintained for each connection in the connection pool), and will be able to proceed till the error comes up again!
Has anyone come across this type of error?
DB2 UDB V8.1 Fixpack 4 on Solaris
Weblogic V8.1 SP2
Thanks
Sireesh.We have seen that error as well. When using entity beans, we could do some creates, but then we would get the Cursor error. It would happen sporadically.
IBM now has better Type 4 drivers with version 8.2, we are having better luck with them then with the BEA drivers. -
JDBC Error: ORA-01000: maximum open cursors exceeded
Post Author: prashant
CA Forum: Information OnDemand
I successfully created reports using CR4E on windows, deployed JSPS to Websphere running on windows and was able to view a large reports for a using JNDI connection resources to Oracle 10g.
Every time report is called, it consume 12 cursors from of the database. Open_cursors count is 300. After 24 or 25 iteration of this report, it throws ORA-01000: maximum open cursors exceeded error.
Has anyone seen this problem, and if so where can I find a hot fix/patch. Any help would very much be appreciated.The following code reproduces the problem for me. I thought this was just related to when an exception occurs, and close occurs immediately afterwards. Close finds the exception that occured, and throws it without releasing the resources.
It's a pain in the ass, that's for sure.
public void go() {
try{
long startTime = System.currentTimeMillis();
String sql = "Select number_7_0__, char_10__, varchar_5__, varchar2_10__, number_10_5__, float_126__, date_, clob_, blob_ FROM lotsofrows";
Properties connectProps = new Properties();
Driver drv = new oracle.jdbc.driver.OracleDriver();
connectProps.put("user", "borg");
connectProps.put("catalog", "test");
connectProps.put("password", "borgborg");
Connection conn = drv.connect("jdbc:oracle:thin:@142.176.134.166:1521:test", connectProps);
int cnt = 0;
while (true) {
try {
System.out.print("\nTest " + ++cnt + " ");
Statement stmt = conn.createStatement();
System.out.print("execute ");
ResultSet rs = stmt.executeQuery(sql);
System.out.print("cancel ");
stmt.cancel();
try {
System.out.print("close.");
stmt.close();
} catch (SQLException se) {
if (se.getMessage().indexOf("requested cancel") != -1) {
System.out.print("URC:Close");
try {
stmt.close();
} catch (Exception ee) {
System.out.println(ee.getMessage());
ee.printStackTrace();
} else {
throw se;
stmt = null;
}catch(Exception se) {
System.out.println(se.getMessage());
se.printStackTrace();
}catch(Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
null -
JDBC Receiver - INPUT CURSOR - Procedure
Hello People!
I've already configured a scenario where a JDBC Receiver channel called a procedure. The procedure had an output cursor and it worked ok!
Now I have to configure a scenario where a JDBC Receiver channel calls a procedure and the procedure has an input cursor. According to SAP (http://help.sap.com/saphelp_nw70/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm) only output cursors are possible. So, how can I pass the data to the procedure, since I have several records to pass to the procedure?
Thanks in advance
JulioTry to change your taget message into multiple statements to be executed once for each record.
-
How to access oracle cursors using jdbc (expecting ur earliest reply)
Hi All,
can anyone help me out by giving me an idea or sample code in accessing the cursors that are defined in the oracle... i have to access those cursors using java... Thanks in advance for your reply and time....
RaguI have tried to follow the example from the URL link you provided.
I'm using :
- Oracle 8.1.6/8.1.7
- JDK 1.3.1
I've created:
create or replace package types
as
type cursorType is ref cursor;
end;
create or replace function sp_ListEmp return types.cursortype
as
l_cursor types.cursorType;
begin
open l_cursor for
select ename, empno
from emp
order by ename;
return l_cursor;
end;
Then I have on my code the following:
import java.sql.*;
import oracle.jdbc.driver.*;
String conStatus = "":
String driver_class = "oracle.jdbc.driver.OracleDriver";
String connect_string = "jdbc:oracle:thin:@slackdog:1521:oracle8";
String query = "begin :1 := sp_listEmp; end;";
Connection conn;
Class.forName(driver_class);
conn = DriverManager.getConnection(connect_string, "scott", "tiger");
try{
conStatus = "before prepareCall, ";
CallableStatement cstmt = conn.prepareCall(query);
conStatus = conStatus + "before Register out, ";
cstmt.registerOutParameter(1,OracleTypes.CURSOR);
conStatus = conStatus + "before execute, ";
cstmt.execute();
conStatus = conStatus + "before getObject, ";
ResultSet rset = (ResultSet)cstmt.getObject(1);
while (rset.next ())
System.out.println( rset.getString (1) );
cstmt.close();
} catch (Exception e) {
conStatus = conStatus + e;
System.out.println(conStatus);
What happens is that I am able to successfully compile the code. But when I run the code, it displays:
"before prepareCall, before Register out, SQLException: incompatible types = -10."
What does that mean? Pls point out to me what I did wrong in my code.
Thanks.
Maybe you are looking for
-
can i run the 64bit version of vista on my 1st gen macbook?
-
Does a foreign key have to be a primary key
Hey all.I was checking on the database code written by sambapos.To my surprise, I found a foreign key that is not a primary key anywhere. Is that possible? If, so why? I am really astonished.
-
Installation of Oracle Application Server on Peer to Peer Network
I have a network of three machines. One of the machine runs Redhat Linux AS 4 with static IP. I have installed Oracle iAS 10g on one machine. Other two machines are windows machines with static IPs. These are client machines for the AS. All three mac
-
Iphone 4 will not restore - download connection time out
i am trying to restore my iphone 4, itunes identifies my iphone, tells me i need to restore and starts to download the latest iOS - gets half way and itunes tells me the network connection has timed out i have tried different USB ports and cables i h
-
Lightroom 3+ (Mac OSX) Spinning Beach Ball on Import only?
Hello -- When I first starting using Lightroom 3 on my 27" quad-core iMac, detection of an inserted memory card (Compact Flash or SDHC) was instantaneous. It's one of the things that really attracted me to Lightroom -- plug in, and go! Sometime