Maximum Open cursor  Exceeded error when deleting records from a table

I have a strange problem.
I have a table EMP_MASTER . Whenever I am trying to delete a record from this table, I am getting Maximum no. of open cursor exceeded error. But this error doesnot come when i delete from any other tables. And no. of open cursor is much lesser than OPEN_CURSOR parameter.
All other tables (around 700) has foreign key constraint to this EMP_MASTER table for created_user paramater.
Is it some thing like, when I am trying to delete a record from EMP_master, implicit cursor opens up and checks all referenced tables. and that limit gets exceeded ?
Please help.
Thanks,
Raj

Raji03 wrote:
There is no trigger defined for this table.
Is there a limit on which no.of references made to a column ? Because one column in this field, Emp no is being referenced in almost every other table. around 700 tables. Will it have any adverse effect ?That should have nothing to do with your problem directly. Again, those tables could have triggers defined on them and you are leaking cursors in one of those triggers (wild guess).
An example of a table with many many others foreign key'd to it.
create table parent_of_everything
   column1 number primary key
insert into parent_of_everything select level from dual connect by level <= 1000;
commit;
--create 1000 tables all with foreign keys to the parent_of_everything
begin
   for i in 1 .. 1000
   loop
      execute immediate 'create table child_' || i || ' (column1 number, column2 number, constraint child_' || i || '_fk foreign key (column1) references parent_of_everything (column1) on delete cascade)';
      execute immediate 'insert into child_' || i || ' select level, mod(level, ' || i || ') from dual connect by level <= 1000';
      commit;
   end loop;
end;
TUBBY_TUBBZ?delete parent_of_everything;
1000 rows deleted.
Elapsed: 00:02:53.03No problems were had (none were expected).
Cleanup script.
--remove the 1000 child tables
begin
   for i in 1 .. 1000
   loop
      begin
         execute immediate 'drop table child_' || i || ' purge';
      exception when others
         then
            null;
      end;
   end loop;
end;
/

Similar Messages

  • ORA-01000: maximum open cursors exceeded--Error

    Hi
    What is "ORA-01000: maximum open cursors exceeded" error,How to solve.
    Thanks
    Miseba

    Hi
    ORA-01000: maximum open cursors exceeded
    Other terms
    Oracle, open cursors, exchange infrastructure
    Reason and Prerequisites
    The parameter "open_cursors" is set too low. Long transactions, such as imports, may use up all available cursors and fail.
    Solution :
    THIS NOTE APPLIES TO XI 3.0 SP2 ONLY **
    if you encounter an exception that reports "ORA-01000: maximum open cursors exceeded" please adjust the open_cursors parameter as follows:
    If the BR*Tools exist on your system:
    1] directory: /usr/sap/<SID>/SYS/exe/run
    2] "brspace -c force -f dbparam -a change -p open_cursors -v 100000"
    3] directory: $ORACLE_HOME/dbs (Unix) or %ORACLE_HOME%/database (Win)
    4] change open_cursors parameter in init<SID>.ora to 100000
    If the BR*Tools are not available (2] above - command not found)
    1] change the open_cursors parameter as in 4] above
    2] restart DB, for changes to take effect. _ NOTE: This problem has been fixed with XI 3.0 SP3 (see note 735078)
    Plz asign points if helpfull.
    Regards
    Padmanabha

  • Maximum open cursors exceeded when inserting to a remote db

    I receive the error:
    ORA-01000: maximum open cursors exceeded
    ORA-02063: preceding line
    from ONTARIO
    (where ONTARIO is my remote db) when I am performing inserts from a pl/sql procedure to the remote db. I am performing two inserts from inside pl/sql and then issuing an explicit commit. I checked the open_cursors init param on both the local db and remote db and it was set to 300. I bumped up the remote db init param to 600. I was able to perform more inserts but still received this error.
    I thought implicit cursors close themselves, especially after a commit. Do I need to do something special to close the cursors on the remote machine?
    Thanks for your time...

    Check which process is making all the cursors on which database. If it is your procedure, try explicitly closing the cursors. I think the cursors are only implicitely closed after the transaction is ended. If you loop and open a cursor within the loop, that might be the problem.
    I also had this problem with Java working over a JDBC connection some time ago on a 815 database. If I recall correctly, that was caused by the JDBC driver and fixed by replacing it with a JDBC driver of 9i.
    The following script is what I used previously in a program that can draw a graph from the results. It is ugly, but does the job.
    Hope this helps,
    L.
    select
      'max cursors',
      to_number(value)
    from
      v$parameter
    where
      name = 'open_cursors'
    union
    select
      substr(lower(username),1,10)||'('||substr(to_char(ses.sid)||','
      ||to_char(serial#),1,9)||')',
      s.value
    from
      v$sesstat s,
      v$statname n,
      v$session ses
    where
    s.statistic#=n.statistic#
    and ses.sid=s.sid
    and n.name like '%cursor%'
    and n.name like '%current%'
    and not (ses.sid between 1 and 6)

  • 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

  • Oracle and "Maximum open cursors exceeded"

    Hi,
    I am using Weblogic 7.0sp2 with Oracle 9.2.0. Since we are using manual JTA
    transactions and the 9.2 drivers are buggy in that respect, we are using the
    9.0.1 thin drivers delivered with weblogic.
    The problem I have is that after a while, we get the now classic "Maximum open
    cursors exceeded" error on connections from our connection pool (used through
    a
    TX datasource). I have of course checked all our JDBC code and it is fine. We
    do not leave any statement/connection open. In fact, I am certain that the
    problem is not caused by our applicative code.
    The reason I am so positive is that the numbers of open (cached) cursors is
    growing, even though there is no activity on our application (I mean no
    activity at all). The number of cursors is regurlarly increasing by one
    every 5 minutes until it reaches the maximum allowed for a session.
    I have listed the statements corresponding to the opened cursors (they
    do not belong to our code, as you might have guessed):
    SELECT sysdate, user from dual
    select longdbcs from javasnm$ where short = :1
    select longname from javasnm$ where short = :1
    As you can see, there are only three different statements. You can get
    the statements from the system view v$open_cursor for a given session
    but it will only give one row per different statement. If you want to know
    the # of opened cursors in your cursor, use v$sesstat with statistic# = 3
    (opened cursor current).
    I suspect something is wrong in the connection testing done by weblogic
    for the pool (I have activated test on reserved connections and test table
    name is "dual") that leaves a resultset/statement behind. What is weird
    though is that the refresh period is still 0 (not 5 minutes as you would
    expect from the cursor growth rate...).
    I would not say that it is an Oracle bug (as stated in some BEA FAQ I read)
    since our application JDBC code does not exhibit the same problem. The
    problem appeared with recent version of WebLogic for which the session
    cursor cache is enabled, I suppose for performance reasons - this
    is set by isssuing "ALTER SESSION SET SESSION_CACHED_CURSORS = ...".
    Talking about this, does anybody know to which value WebLogic sets this
    parameter when intializing the connection (this is neither
    documented/configurable)?
    Up to now, I have come up with possibly two workarounds, neither of which
    is satisfying:
    - resetting the pool from time to time
    - issuing "ALTER SESSION SET SESSION_CACHED_CURSORS = 0" when I get a
    connection from the pool. I have not tested this one personally (read
    in a newsgroup that someone else did successfully) but it is supposed
    to reset the cursor cache that is causing the trouble.
    Any help will be greatly appreciated,
    Regards,
    Thierry.

    Thierry Rouget wrote:
    Hi,
    I am using Weblogic 7.0sp2 with Oracle 9.2.0. Since we are using manual JTA
    transactions and the 9.2 drivers are buggy in that respect, we are using the
    9.0.1 thin drivers delivered with weblogic.
    The problem I have is that after a while, we get the now classic "Maximum open
    cursors exceeded" error on connections from our connection pool (used through
    a
    TX datasource). I have of course checked all our JDBC code and it is fine. We
    do not leave any statement/connection open. In fact, I am certain that the
    problem is not caused by our applicative code.
    The reason I am so positive is that the numbers of open (cached) cursors is
    growing, even though there is no activity on our application (I mean no
    activity at all). The number of cursors is regurlarly increasing by one
    every 5 minutes until it reaches the maximum allowed for a session.
    I have listed the statements corresponding to the opened cursors (they
    do not belong to our code, as you might have guessed):
    SELECT sysdate, user from dual
    select longdbcs from javasnm$ where short = :1
    select longname from javasnm$ where short = :1
    As you can see, there are only three different statements. You can get
    the statements from the system view v$open_cursor for a given session
    but it will only give one row per different statement. If you want to know
    the # of opened cursors in your cursor, use v$sesstat with statistic# = 3
    (opened cursor current).
    I suspect something is wrong in the connection testing done by weblogic
    for the pool (I have activated test on reserved connections and test table
    name is "dual") that leaves a resultset/statement behind. What is weird
    though is that the refresh period is still 0 (not 5 minutes as you would
    expect from the cursor growth rate...).
    I would not say that it is an Oracle bug (as stated in some BEA FAQ I read)
    since our application JDBC code does not exhibit the same problem. The
    problem appeared with recent version of WebLogic for which the session
    cursor cache is enabled, I suppose for performance reasons - this
    is set by isssuing "ALTER SESSION SET SESSION_CACHED_CURSORS = ...".
    Talking about this, does anybody know to which value WebLogic sets this
    parameter when intializing the connection (this is neither
    documented/configurable)?
    Up to now, I have come up with possibly two workarounds, neither of which
    is satisfying:
    - resetting the pool from time to time
    - issuing "ALTER SESSION SET SESSION_CACHED_CURSORS = 0" when I get a
    connection from the pool. I have not tested this one personally (read
    in a newsgroup that someone else did successfully) but it is supposed
    to reset the cursor cache that is causing the trouble.
    Any help will be greatly appreciated,
    Regards,
    Thierry.Hi. We don't make those queries either. I suspect they are internal to the
    oracle driver. One thing you can try is to set the size of the pool's
    statement cache to zero. Oracle will retain cursors for every statement we
    cache. The alternative is also to tell the DBMS to allow a given session
    more cursors.
    Joe

  • Maximum Open Cursors Exceeded problem in XSQL

    Hi,
    We are processing an XSQL page by calling XSQLRequest.process() programatically within our application. Within the XSQL page there are several queries which involve multiple nested CURSOR expressions... when the query returns enough rows we are running into the error "ORA-00604: error occurred at recursive SQL level 1 ORA-01000: maximum open cursors exceeded".
    When searching this forum I have seen many (old) postings regarding this error and a bug in the XDK... seems like it was some time ago, but while we set about improving the structure of our XSQL page (or increasing the max open cursor init parameter currently at 500 or both) can anyone confirm that this bug no longer exists?
    Also, any general suggestions on working around this limit rather than increasing it? We have considered splitting up our queries into smaller queries (and merging the results via XSLT) and closing cursors during the session explicitly by issuing commits within the XSQL page... but any better ideas?
    Thanks,
    Bob

    I have found this max open cursors problem to be related to Statement object not being closed. This presents a problem for the use of PreparedStatements, because they are only useful if you can keep them open and resuse them. However, in doing so, each iteration through the PreparedStatement creates another open cursor in the databse rather than reusing the previous one. A work around I discovered by reading about REF CURSORS and I use in JDBC is as follows:
    Assuming a previously prepared PreparedStatement pstmt and a ResultSet rset-
    while (rset.next()) {
    rset.close();
    // This line closes the cursor in the database
    // but does not require you to re-prepare the
    // PreparedStatement. Don't ask me why--ask the
    // Oracle API guys.
    rset.getStatement().close();
    // make ready for GC
    rset = null;

  • ORA-01000: maximum open cursors exceeded In a Package

    I have a package that is utilizing cursors, This program is for a data conversion project. I have Ten procedures and functions in this package, about 4 of them are public. Within my main program I call these functions and procedures as needed. After about the processing of 30 records, i get this 'ORA-01000: maximum open cursors exceeded' error. the curosr parameter on the database is 300, I am not sure what to do, the cursors are closed, because I am usuing the cursor for loop. I have changed these cursors from ref to regular cursors, but the problem persist. Could someone please help! Thanks.

    there are about 6000 lines of code here is an example. I have checked all cursors and they are closed after processing.
    -- Package Spec
    Package MainPac Is
    Procedure c1;
    End MainPac;
    -- Package Body
    Package MainPac Is
    Procecudure P2( InputP ) is
    Cursor c2 is select * from SiteRec
    Where NJSKey = InputP;
    For c2Rec In C2 Loop
    Process c2Rec;
    For C3Rec in (Select Remart Text from all_remarks
    Where remark_Key = C3Rec.Key) Loop
    Load into tem table;
    End loop;
    end Procedure P2;
    Procecudure P3( InputP ) is
    Cursor C4 is select * from SolutuinsTab
    Where NJSKey = InputP;
    For C4Rec In C4 Loop
    Process C4Rec;
    For C5Rec in (Select Remart Text from all_remarks
    Where remark_Key = C4Rec.Key) Loop
    Load into tem table;
    End loop;
    end Procedure P3;
    Procedure c1 is
    Cursor c1 is Select * from NJS;
    begin
    For c1rec in c1 loop
    process c1rec;
    call procecudure P2(NJSKey);
    call procecudure P3 (NJSKey);
    call procecudure P4(NJSKey);
    call procecudure P5(NJSKey);
    call procecudure P6(NJSKey);
    end loop;
    End MainPack ;

  • ORA-01000 maximum open cursors exceeded with XA driver

    We are getting ORA-01000 maximum open cursors exceeded error from Oracle database
    agian and again.We are usimg XA driver.
    What is the weblogic's work around to handle this error?How we can handle this?We
    tried doing "grant select on DBA_PENDING_TRANSACTIONS to public ;" ,this also
    works for some time only.Again the same error starts coming.
    Help please.
    Thanx in advance.

    Thanks for your reply.
    I have increased my cursor size to 2000(default 300).We are using weblogic6.1
    and Oracle9i.Yes I was little aware about this bug so I tried doing "grant select
    on DBA_PENDING_TRANSACTIONS to public " from sys and no of open cursors reduced
    drastically but aftter some time increased again.We are using combination of thin,XA,non
    XA and oci drivers.
    We are using weblogic security framework also in our application and I think that
    consumes maximum no. of cursors.
    Kindly advice.
    Thanx a lot.
    Pinky
    Mitesh Patel <[email protected]> wrote:
    What is the size of cusror set in your oracle init.ora file?
    What version of oracle thin driver and weblogic are you using?
    Please read the following note:
    There is a bug with Oracle 817 driver's XAResource.recover implementation:
    it
    ignores the flag and always return all in-doubt Xids. After initially
    calling a resource's recover with TMSTARTRSCAN, TM subsequently calls
    the
    resource's recover with TMNOFLAGS until no more Xid is returned. Thus,
    Oracle driver's XAResource.recover is called infinitely until eventually
    it
    returns XAER_RMERR. Subsequent XAResource.start then returns ORA-01000
    exception (looks like all their XAResource methods internally uses prepared
    statements to execute some stored procedure.)
    Is this the case wth you?
    Mitesh
    Pinky Arora wrote:
    We are getting ORA-01000 maximum open cursors exceeded error from Oracledatabase
    agian and again.We are usimg XA driver.
    What is the weblogic's work around to handle this error?How we canhandle this?We
    tried doing "grant select on DBA_PENDING_TRANSACTIONS to public ;",this also
    works for some time only.Again the same error starts coming.
    Help please.
    Thanx in advance.

  • ORA-01000: maximum open cursors exceeded in R12

    Hi,
    In which Middle Tier log we see "ORA-01000: maximum open cursors exceeded" error, we have EBS R12 version.

    937828 wrote:
    Hi,
    In which Middle Tier log we see "ORA-01000: maximum open cursors exceeded" error, we have EBS R12 version.
    Increase the value of OPEN_CURSORS init parameter -- https://community.oracle.com/search.jspa?peopleEnabled=true&userID=&containerType=&container=&q=ORA-01000
    Database Initialization Parameters for Oracle E-Business Suite Release 12 (Doc ID 396009.1)
    Thanks,
    Hussein

  • Error During Delete Of Application:ORA-01000: maximum open cursors exceeded

    Hello All.
    I am using Apex version 3.2.0.00.27. I am trying to delete an existing application (App_ID 116). I am continually getting ORA-01000: maximum open cursors exceeded.
    Prior to deleting this application, I attempted to, instead, import (that is, replace) this app with a previously saved Apex app (APP_ID 116). This previously saved app is also at the same version. I get the same error. At that point, I figured that I would delete the app and then import my previously saved app, only to get the same error.
    I then attempted to import the previously saved app as a new APP_ID (256). This time, the app imported without error.
    Does anyone know what is going on? Could it be that my existing app 116 is "corrupted" (whatever that means)? Why can't I delete or import over my existing app 116?
    Any help would be appreciated.
    Thank you.
    Elie

    Post Author: amr_foci
    CA Forum: Information OnDemand
    its a database related Error and it can be fixed
    please check this link
    http://publib.boulder.ibm.com/infocenter/wasinfo/v4r0/index.jsp?topic=/com.ibm.support.was.doc/html/EJB_Container/1040875.html
    good luck
    Amr

  • In java/jsp got Error,ORA-01000: maximum open cursors exceeded,

    Dear ALL,
    We are facing a problem of in java/jsp. ORA-01000: maximum open cursors exceeded,We are using referance Cursor for returing the Record in java file.
    The Code is given below.
    import java.sql.*;
    import javax.sql.*;
    import com.india.trade.dbConnection.*;
    import oracle.jdbc.driver.*;
    import java.util.Vector ;
    public class IntRmsActivity
         private static JDBCConnection instance = null;
    private static Connection con = null;
         private static CallableStatement stmt_admin_getadmins = null;
         private static String str_admin_getadmins = "{ call Admin_conf.RMS_ADMIN_GETALLADMINS(?,?) }";
         static
              try
                   instance = new JDBCConnection();
                   con = instance.getConnection();
                   stmt_admin_getadmins = con.prepareCall(str_admin_getadmins);
    }catch(Exception se){se.printStackTrace();}
         public static Vector admin_getAdmins() throws Exception
              checkconnection();
              String message = null;
              Vector v_admins = new Vector();
              ResultSet rs_admins = null;
              stmt_admin_getadmins.registerOutParameter(1 , OracleTypes.CURSOR);
              stmt_admin_getadmins.registerOutParameter(2 , Types.VARCHAR);
              stmt_admin_getadmins.execute();
              message = stmt_admin_getadmins.getString(2);
              System.out.println("message " + message);
              rs_admins = ((OracleCallableStatement)stmt_admin_getadmins).getCursor(1);
              while (rs_admins.next())
                        v_admins.addElement(rs_admins.getString("adminid"));
              rs_admins.close();
              return v_admins;
    CREATE OR REPLACE PACKAGE Admin_conf IS
    TYPE REF_CRSR IS REF CURSOR; /* OUTPUT CURSOR VARIABLE TYPE */
    PROCEDURE RMS_ADMIN_GETALLADMINS(RESULTS OUT REF_CRSR,
                                            OUT_MESSAGE OUT VARCHAR2);
    END Admin_conf;
    CREATE OR REPLACE PACKAGE BODY Admin_conf
    IS
    PROCEDURE RMS_ADMIN_GETALLADMINS(RESULTS OUT REF_CRSR,
                                            OUT_MESSAGE OUT VARCHAR2)
    IS
    l_ref_out_crsr REF_CRSR;
    BEGIN
         OPEN l_ref_out_crsr FOR
         SELECT EXECUTIVE_ID adminid
         FROM MASTER_EXECUTIVE_ID
         ORDER BY EXECUTIVE_ID;
         OUT_MESSAGE := 'ADMIN IDS FETCHED SUCCESSFULLY';
         RESULTS := l_ref_out_crsr;     
    EXCEPTION WHEN OTHERS THEN
              OUT_MESSAGE := 'ERROR ' || SUBSTR(SQLERRM, 1, 60);
    END RMS_ADMIN_GETALLADMINS;
    END Admin_conf;
    Regards
    Ajay Singh Rathod

    Are you actually closing the connections, resultsets in all cases?
    From what you've posted you call
    rs_admins.close();but in that method, you propagate any exceptions that occur out to the caller method, which in turn just prints a stack trace.
    So if an exception occurs before you call the rs_admin.close() the result set will never be closed as the statement won't be reached.
    I'd add a speific exception handling routine to the admin_getAdmins() method and include a finally clause to close the result set in all cases. You can still onthrow the exception if you want.
    cheers
    -steve-

  • Getting error ora-01000 maximum open cursors exceeded

    hello,
    i am building my fist application using eclipse3.3 hibernate 3.2(hybernatesynchronizer as plugin)
    i have a oracle9i like sgbd . when i trying to create my mapping file from eclipse i got this error :
    ORA-01000: maximum open cursors exceeded
    i try to increase the number of cursor from the oracleconfiguration file init.ora, i shutdown but the problem still
    i don t know how to solve this problem really.
    i need help.

    Yes, that it what I was asking about.Not that it matters, but I think you misunderstood. I meant "if you ask it to leak resources then it will do so." I wasn't asking what you meant.
    Is there a way to make it explicitly open and close via a single call? Perhaps a configuration option either globably or by method/class?Not as a standard part of Hibernate, no. That said, it's relatively hard to leak anything other than connection objects unless you're really trying hard. There are libraries that you can use to manage the lifetime of the connection (actually the session) object. I like the Spring DAO support classes. Inevitably they cause their own problems for someone who doesn't understand what Hibernate's up to under the covers though.
    Edit: Quick example
    // Bog standard Hibernate
    Session session = sessionFactory.openSession();
    try {
       return (List<Foo>)session.createQuery("from Foo").list();
    } finally {
       session.close(); // If omitted will leak a connection object
    // Using Spring
    return (List<Foo>)getHibernateTemplate().find("from Foo");Things get slightly more interesting if you're using lazy loading and actively want to keep the connection around for longer.

  • Error ORA-01000: maximum open cursors exceeded

    Why Oracle return this error. When I change the OPEN_CURSORS in init.ora from 100 to 1000 without this error.
    I want to keep Minimum cursors value. How can I change the Java program ?
    96 er_write_asp('W349','HK','50112','USD',3.99)
    97 er_write_asp('W349','HK','10112','USD',5.22)
    98 er_write_asp('W349','HK','60112','EUR',13.07)
    99 er_write_asp('W349','HK','50112','USD',3.9)
    100 er_write_asp('W349','HK','40112','USD',5.65)
    101 er_write_asp('W349','HK','90112','USD',2.75)
    java.sql.SQLException: ORA-01000: maximum open cursors exceeded
    ORA-06512: at "POSTCAL.ER_WRITE_ASP", line 10
    ORA-06512: at line 1
    java Program list.
         eric.leung 2003/12/02
         set CLASSPATH include C:\Oracle\Ora81\jdbc\lib\classes12.zip
         Purpose
         ===============
         Read text file, write into Oracle Database
    import java.io.*;
    import java.util.StringTokenizer;
    import java.sql.*;
    import java.lang.*;
    import java.math.BigDecimal;
    import java.util.Date;
    public class writeASP {
    // Login Information
    static String user = "x";
    static String passwd = "x";
    static String ip = "x";
    static String getfile = "c:\\temp\\asp.csv";
    public static void main(String[] args) throws IOException {
         String line;
         int i = 0;
         int cnt = 0;
         int port = 0;
         Connection conn;
         Statement stmt;
         String query = "";
         String strone = "";
         String arry[] = {"","","","","","","","","","","","","","",
         // start to connection
         chkArgs(args);     
         FileReader inFile = new FileReader(getfile);
         BufferedReader in = new BufferedReader(inFile);
         try {                
         Class.forName("oracle.jdbc.driver.OracleDriver");
         conn = DriverManager.getConnection("jdbc:oracle:thin:@" + ip + ":1521:lcdx",
              user,passwd);
         stmt = conn.createStatement();
         while((line= in.readLine()) != null)
                   cnt = cnt + 1;
                   StringTokenizer mot = new StringTokenizer(line,",");
              if (mot.countTokens() > 0) {                   
                        for (i = 0; 0 < mot.countTokens() ;i++) {
                             arry[i+1] = "";
                             arry[i] = mot.nextToken();
                        } /* for */
                   } /* if */           
                   strone = arry[0].substring(0,1);
                   if (strone.equals("W")) {
                        //abc(arry);
                        query = "er_write_asp(" +
                        quote(arry[0],',') +
                        quote(arry[1],',') +
                        quote(arry[2],',') +
                        quote(arry[3],',') ;
                        query = query + arry[4] + ")";               
                   System.out.println(cnt + " " + query);
                   CallableStatement cs = conn.prepareCall
                        ("{call er_write_asp(?,?,?,?,?)}");
                   cs.setString(1,arry[0]);
                   cs.setString(2,arry[1]);
                   cs.setString(3,arry[2]);
                   cs.setString(4,arry[3]);
              try {cs.setBigDecimal(5, new BigDecimal(arry[4])); } /*pur_cost */
              catch(NumberFormatException e) {cs.setDouble(5,0);}
                   // System.out.println("Call string: "+ cs.getString());
                   boolean flag = cs.execute();
                   // ResultSet rs = cs.executeQuery();
                   // stmt.executeUpdate();
                   } /* if */
         } /* while */
         conn.close();
         } /* try */
         catch (Exception e) {
              System.err.println(e.toString());          
              } /* Catch */
         in.close();     
    } /* main */
    public static void abc(String g[])
         System.out.print(g[0] + " " + g[1] + " "
              + g[2] + " " + g[3] + " " + g[4] + " "
              + g[5] + " " + g[6] + " " + g[7] + " "
              + g[8] );     
         System.out.println();
    private static String quote(String s)
         return "'" + s + "'";
    private static String quote(String s,char j)
         return "'" + s + "'" + j;
    public static void chkArgs(String[] args) {
         for (int j=0 ; j < args.length;j++) {
              if (args[j].trim().equals("-u")) {
                   if (j + 1 < args.length) {
                        try { user = args[j+1];}
                             catch ( Exception e) {}
              } /* if */
              if (args[j].trim().equals("-p")) {
                   if (j + 1 < args.length) {
                        try { passwd = args[j+1];}
                             catch ( Exception e) {}
              } /* if */
              if (args[j].trim().equals("-i")) {
                   if (j + 1 < args.length) {
                        try { ip = args[j+1];}
                             catch ( Exception e) {}
              } /* if */
              if (args[j].trim().equals("-f")) {
                   if (j + 1 < args.length) {
                        try { getfile = args[j+1];}
                             catch ( Exception e) {}
              } /* if */
              if (args[j].trim().equals("-h")) {
                   help();
                   System.exit(0);
              } /* if */
         } /* for */
    } /* chkArgs */
    public static void help() {
         System.out.println("\nWrite ASP Price Version 1.0 2003/12/02\n");
         System.out.println("Option:");
         System.out.println("\t-i IP Address");
         System.out.println("\t-u User name");
         System.out.println("\t-p Password");
         System.out.println("\t-f File name");
         System.out.println("\t-h Help");
         System.out.println("\nCall Oracle Stored Procdure");
         System.out.println("er_write_ASP(,,,,)");
    } /* help () */
    } /* Class */

    Don't create a new callable statement each pass through the loop. Create it outside the loop and set the parameters & exec inside the loop. Close the resultset each time. Close statement after loop.

  • The error:maximum open cursors exceeded,how to resolve it??

    the parameter is as following in oracle: open_cursors=300
    i write the following two methos get data from oracle db,after invote the methods many times,the program thrwos the exception named "maximum open cursors exceeded";why?how to resolve it?
    in my program ,i have closed the statment and resultset!
    the following is the code,and method a call mehtod b:
    mehtod a:
    //modeify the product and call mothod b
    public boolean modifyDVBProd(Integer prodIDInt,ProdRequestEn prod)
    boolean successB=false;
    Connection conn=...;
    if(conn!=null)
    try
    conn.setAutoCommit(false);
    //the following call method b
    successB=ProdOperateBL.getInstance().modifyDVBProd(conn,prodIDInt,prod);
    if(successB)
    conn.commit();
    else
    conn.rollback();
    catch(Exception e)
    successB=false;
    try
    conn.rollback();
    catch(Exception ex)
    ex.printStackTrace();
    e.printStackTrace();
    finally
    try
    conn.setAutoCommit(true);
    catch (SQLException ex)
    ex.printStackTrace();
    else
    successB=false;
    return successB;
    method b;��
    //modify products
    public boolean modifyDVBProd(Connection conn,Integer prodIDInt,ProdRequestEn prod)
    boolean successB=false;
    String sqlPriceStr="UPDATE pricemodelen pm SET pm.rentpricf=? WHERE pm.priceidl=(SELECT p.priceidl FROM producten p WHERE p.productidl=?)";
    String sqlProdStr="UPDATE producten p set pronamestr=?,prod_type=?,unidstr=?,catype_name=?,casid=?,entitle_code=?,validfrdt=?,validtodt=?,descstr=? WHERE P.productidl=?";
    String sqlProd_channelDelStr="DELETE FROM proden_channelen c WHERE c.productidl=?";
    String sqlProd_channelInsertStr="INSERT INTO proden_channelen(productidl,channel_id) VALUES(?,?)";
    PreparedStatement pstmt1=null;
    PreparedStatement pstmt2=null;
    PreparedStatement pstmt3=null;
    PreparedStatement pstmt4=null;
    int paramIndexInt=1;
    try
    //price
    pstmt1=conn.prepareStatement(sqlPriceStr);
    pstmt1.setDouble(paramIndexInt++,prod.getProdPriceD());
    pstmt1.setDouble(paramIndexInt++,prodIDInt.intValue());
    int priceResult=pstmt1.executeUpdate();
    //product
    pstmt2=conn.prepareStatement(sqlProdStr);
    paramIndexInt=1;
    pstmt2.setString(paramIndexInt++,prod.getProdNameStr()); //product name
    pstmt2.setInt(paramIndexInt++,prod.getProdTpInt());//product type
    pstmt2.setString(paramIndexInt++,prod.getPriceUnitStr());//unit
    pstmt2.setString(paramIndexInt++,prod.getCaTpStr());//type
    pstmt2.setInt(paramIndexInt++,prod.getCasidInt());//casid
    pstmt2.setString(paramIndexInt++,prod.getCaEntitleCodeStr());//caentitlecode
    pstmt2.setDate(paramIndexInt++,prod.getValidBeginDate());//time
    pstmt2.setDate(paramIndexInt++,prod.getValidEndDate());//time
    pstmt2.setString(paramIndexInt++,prod.getProMemoStr());//memo
    pstmt2.setInt(paramIndexInt++,prodIDInt.intValue());//id
    int prodResult=pstmt2.executeUpdate();//
    pstmt3=conn.prepareStatement(sqlProd_channelDelStr);
    pstmt3.setInt(1,prodIDInt.intValue());
    pstmt3.executeUpdate();
    int channelResult=0;
    for(int i=0;i<prod.getChannelIDsInt().length;i++)
    pstmt4=conn.prepareStatement(sqlProd_channelInsertStr);
    pstmt4.setInt(1,prodIDInt.intValue());
    pstmt4.setInt(2,prod.getChannelIDsInt());
    pstmt4.addBatch();
    pstmt4.executeBatch();
    //((OraclePreparedStatement)pstmt).sendBatch(); // JDBC sends the queued request
    if((prodResult>0)&&(priceResult>0))
    successB=true;
    catch(Exception ex)
    successB=false;
    ex.printStackTrace();
    finally
    //closing the preparedstatement
    try
    if(pstmt1!=null)
    pstmt1.close();
    if(pstmt2!=null)
    pstmt2.close();
    if(pstmt3!=null)
    pstmt3.close();
    if(pstmt4!=null)
    pstmt4.close();
    catch (SQLException ex)
    ex.printStackTrace();
    return successB;

    Check this loop.
    or(int i=0;i<prod.getChannelIDsInt().length;i++)
    pstmt4=conn.prepareStatement(sqlProd_channelInsertStr);
    pstmt4.setInt(1,prodIDInt.intValue());
    pstmt4.setInt(2,prod.getChannelIDsInt());
    pstmt4.addBatch();
    Here every time the loop executes, a new statement object is created and assigned to the same statement object reference pstmt4. So finally when u r closing the stmt objects, only one stmt object gets closed out of prod.getChannelIDsInt().length that gets created with in the loop.

  • Maximum open cursors exceeded when reversing

    He llo,
    I get the following zrror when trying to reverse a table from an Oracle Database preventing me to reverse the table:
    java.sql.SQLException: ORA-01000: maximum open cursors exceeded
    Thanks

    Hi Jean,
    I think this is related to the issue I faced a while back.
    Thread: Limit/remove inactive database connections generated by ODI
    My solution was to write a custom linux shell script to kill off old ODI sessions in the database. I scheduled this job to run via the crontab.
    sqlplus -s / <<!
    set feedback off
    set trimspool on
    set pages 9999
    spool /tmp/kill_odi_db_sessions.tmp
    select 'ALTER SYSTEM KILL SESSION '''||sid||','|| serial#||''' immediate;'
    from v\$session
    where username ='<ODI_USER>'
    and status ='INACTIVE'
    and LAST_CALL_ET > 1800
    spool off
    exit
    sqlplus -s / <<!
    @/tmp/kill_odi_db_sessions_$ORACLE_SID.tmp
    exit
    Hope this helps!
    Matt

Maybe you are looking for

  • Printer driver for Hp Color LaserJet 1600 ???

    I have an Hp Color LaserJet 1600 printer. Best printer i ever had. Where can I find printer driver ? Checked a few Hp and apple site and every printer inthe world except this one seem to have a driver. my OS is 10.8.4

  • What format do i need to download a book

    Can i download books from free sites onto my ipad or do i need to convert them

  • Using variable in connection string returns 0 for variable.

    hi all- I am pulling data from a visual forxpro database and the connection string is as follows:  Data Source=\\ServerName\FolderName\AR;User ID=Domain\svcAct;Provider=VFPOLEDB.1;Persist Security Info=True; I created a variable called CurrentARPath

  • Webhelp right pane not displaying in IE10 for Windows 7

    Hello, I'm using Robohelp 9 - HTML, and generating Webhelp using IE10 on Windows 7. When I generate the help, the default topic displays. However, if I click any page within a book, the right-pane displays blank. But, if I make the browser window sma

  • SCHEMA: Flat vs. hierarchical

    All, I'd like your feedback on another topic relating to the schema, this one at a higher level. Basically, the question is whether you think we should adopt a flat schema, or a hierarchical schema. To explain: - With a flat schema, we assign some nu