Catching a particular SQL Exception

Hi
I am getting an SQLException ORA-01653: unable to extend table.
Is there any way so that I can catch this particular exception only.
If I have a catch block
catch(SQLException e)
System.out.println(e);
The above will be general and for all sql exception, I want to only catch ORA 01653 exception
Thanks

No, but what you can do is to test if this is the exception you want to special case in a local try - catch, then rethrow the exception if it's not a match.

Similar Messages

  • Catching SQL Exceptions

    Hi all,
    I have a bit of java code which is performing an SQL insert on a table. There is a possibility of a database foreign key exception being generated on this insert statement. I wish to catch this particular exception, log it and then ignore it and move to the next statement. Currently the code is catching SQLException, is a foreign key exception something that I can uniquely catch, or is it rolled up into SQLException. I haven't had luck finding any docs on this subject, any help would be appreciated.
    Thanks.

    Maybe I'm not understanding something here but is it
    not a bit dodgy to be relying on the presence of a
    foreign key constraint on the DB to raise the problem
    in the client? Personally I would be writing code to
    check if a foreign key constraint error will be raised
    by the inserting of the record. I will admit though
    that this could be a bit clunky and more time
    consuming (checking through select statement then
    doing insertion if OK) as well as a possible insertion
    of the record just after your select statement
    returned saying that you couldn't insert the record
    because a foreign key constraint would be raised.I disagree. IMHO, the OP's way of doing it is the proper approach--let the database worry about the data integrity. It's made to be very good at that, and that's where the constraints are defined. If you put that code in the client, you have to duplicate the constraints you put into your DDL in your client code.

  • How to catch SQL Exceptions in JSP

    Hi,
    I wanted to know how do we catch the correct SQL return code in a JSP page ?
    Based on the return code I wanted to display customised Error messages.
    But I could'nt figure out a way to get the error message returned by the underlying DB2
    database.
    I am using Websphere Application Server and the backend database is DB2.

    The only way I am aware of is parsing the exception message/the call stack.

  • How to throw or catch sql exception for executeReader sql adapter

    Wcf sql adapter was created and executeReader was used.
    When an invalid sql statement was constructed and send it to wcf sql adapter, it will hanging there, and no response. No exception was catched even though send chape  was inside a catch block. How can I catch this kind of exception
    or throw this exception ? I need to give client an exception resposne.
    thanks
    Gary

    I used scope with exception handle which has Exception object type: "System.SystemException".
    I guess this type "System.SystemException" can catch any exception, including sql exception. Maybe I am wrong. I got error from window event:
    A message sent to adapter "WCF-Custom" on send port "WcfSendPort_SqlAdapterBinding_DalCore_Custom" with URI "mssql://shig-quad-2k3e1//DataSourceOne?" is suspended.
     Error details: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
    Server stack trace:
       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndRequest(IAsyncResult result)
    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at System.ServiceModel.Channels.IRequestChannel.EndRequest(IAsyncResult result)
       at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.RequestCallback(IAsyncResult result)
     MessageId:  {B24EF5B8-298A-4D4F-AA98-5E639361A7DB}
     InstanceID: {F8924129-265B-4652-B20E-8D25F8F20A51}
    If  "System.SystemException" can't catch all exception, which type can catch all exception ? I want to catch all exception in this catch block.
    thanks
    Gary

  • Catching sql exception

    Hi,
    Is there any other way to catch primary key violation error other than catching the sql exception and checking the pattern in the exception trace.
    Thanks in advance,

    Basil wrote:
    Hi,
    Is there any other way to catch primary key violation error other than catching the sql exception and checking the pattern in the exception trace.You could try looking at the SQL state or vendor code from the SQL exception. They might have more information, along the lines of what you are looking for.
    If you are looking to avoid the exception altogether forget it. You could do a SELECT before INSERT but that of course isn't concurrency "safe" and generally is just a waste of time.
    PS In future JDBC related questions should be posted into the JDBC forum. Selecting the best forum for your question gives you a better chance of getting better answers faster.

  • How to capture the exact SQL exception for failure to connect to database

    Hi, i would like to capture the exact exception for failure to connect to a Oracle 9i database (via JDBC). I learnt that there is specific code or exception that can be captured, so that a more proper error message can be thrown out like "Failure to connect to database" can be displayed. Anyone know how to go about doing it? thanks

    That depends on your database vendor, I believe. (Unless there's a SQL standard for states and codes that I'm unaware of.)
    Personally, I wouldn't worry about "catching" a particular code. (You've already caught the exception - that's the best you can do.) I'd report the error code and state and just look up what it means when I got one.
    Hopefully you won't be catching exceptions. They're supposed to be rare. - MOD

  • Pl/sql exception not caught.

    This program should give me an error "table or view does not exist" caught by the pl/sql exception, as dba_data_file1 table does not exist.
    However all that it returns is Input truncated to 3 characters
    Q1. Why?
    Q2. How can I remove this message "Input truncated to 3 characters. Where is this message comming from?
    #!/bin/ksh
    sqlplus -s << EOF
    abc/[email protected]
    set pages 0
    SET SERVEROUTPUT ON BUFFER 100000000
    BEGIN
    dbms_output.ENABLE(1000000);
    SELECT
    round(sum(bytes)/1024/1024/1024),
    round(sum(free_bytes)/1024/1024/1024),
    TRUNC(SYSDATE)
    from
    (SELECT tablespace_name, BYTES, 0 FREE_BYTES FROM dba_data_files1
    UNION ALL
    SELECT tablespace_name, 0, BYTES FROM dba_free_space
    union all
    SELECT tablespace_name, BYTES, 0 FROM dba_temp_files
    union all
    SELECT 'REDO-LOGS', b.BYTES, 0
    FROM v\\$logfile a, v\\$log b
         WHERE
    a.GROUP# = b.GROUP#);
         dbms_output.put_line("ok ");
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line("Error "||SQLERRCODE ||":"|| SQLERRM);
    exit 1
    END;
    exit 0
    EOF
    $> tstrun.ksh
    Input truncated to 3 characters

    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line("Error "||SQLERRCODE ||":"|| SQLERRM);
    exit 1
    END;
    if you catch exception, process it then you must reraise it. its a general mistake found when you are using others instead of name exception, so remember whenever you use others you must reraise the exception

  • SQL exception in OAF Controller

    Hi
    I am getting SQL exception error with the following query in OAF Controller.
    Can anyone tell me the issue with the follwoing query,
    PreparedStatement cal = conn.createPreparedStatement(" SELECT count(1) " +
    " FROM hz_parties hp, hz_cust_accounts_all hca, hz_cust_acct_sites_all hcas " +
    " WHERE hca.party_id = hp.party_id " +
    " AND hp.party_name = '"+partyName+"'" +
    " AND hcas.cust_account_id = hca.cust_account_id " +
    " AND hcas.org_id = 14078 " +
    " AND oapagecontext.getOrgId() != 14078 ",1);
    catch(SQLException sqle)
    lcount = String.valueOf(0);
    exceptions.add(new OAException("Error in the custom query, Contact Administrator" , OAException.INFORMATION));
    OAException.raiseBundledOAException(exceptions);
    }

    Myself fixed by removing the profile org id from query and put it outside

  • Sql exception occurred during pl/sql upload error in custom integrator

    Hi,
    I have modified custom integrator which was working fine. I have added one column in template and the lov is working fine.
    Issue is that when i upload the file to oracle it showing error as ''sql exception occurred during pl/sql upload".
    I have tried executing the same from back end but it was working fine from back end and inserting properly in interface table.
    Kindly suggest for the issue.
    Regards,
    Gk

    Hi,
    You can get the error message in excel sheet itself by using the following piece of code.
    FND_MESSAGE.CLEAR;
    FND_MESSAGE.SET_NAME ('APPLICATION', 'APPLICATION_MESSAGE_NAME');
    FND_MESSAGE.SET_TOKEN ('ERROR_TOKEN', ERROR MESSAGE);
    FND_MESSAGE.RAISE_ERROR;
    Create an excpetion block and include the above piece of code whilde catching the exception.
    APPLICATION- The applicatio in which you create message
    APPLICATION_MESSAGE_NAME-  The message Name
    ERROR_TOKEN- You must create a token in application message
    ERROR MESSAGE- You can see the  error using SQLERRM.
    Thanks,
    Vinoop

  • Sql exception when connecting to oracle database

    When trying to connect to an oracle database using the code below i get an sql error. i put the code below it and the stack trace below the code. any help would be great
    Connection connection = null;
            try {
                // Load the JDBC driver
                String driverName = "oracle.jdbc.driver.OracleDriver";
                Class.forName(driverName);
                //  Create a connection to the database
                String serverName = "192.168.0.2";
                String portNumber = "1158";
                String sid = "orcl";
                String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
                // String url = "jdbc:oracle:oci:@orcl";
                String username = "system";
                String password = "mmsi";
                connection = DriverManager.getConnection(url, username, password);
            } catch (ClassNotFoundException e) {
                System.out.println("Class Not Found Exception in connection to db");
            } catch (SQLException e) {
                System.out.println("SQL Exception in connecting to Database ");
                e.printStackTrace();
    stackTrace------------------------------------------------------------------------------
    java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    SQL Exception in connecting to Database
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
    before this.start
    got to doaction
            at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:420)
            at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
            at java.sql.DriverManager.getConnection(DriverManager.java:525)
            at java.sql.DriverManager.getConnection(DriverManager.java:171)
            at mmsiserver.conversation.<init>(conversation.java:190)
            at mmsiserver.Server.run(Server.java:105)
    Exception in thread "Thread-0" java.lang.NullPointerException
            at mmsiserver.conversation.doAction(conversation.java:218)
            at mmsiserver.conversation.<init>(conversation.java:202)
            at mmsiserver.Server.run(Server.java:105)Message was edited by:
    pcpitcher1

    Please read this
    http://forum.java.sun.com/thread.jspa?threadID=512566&start=0&tstart=0

  • VO Errors ,,,,, procedurejava.lang.sql.exception & Java.lang.NullPointerExc

    Hi All,
    I have extended the standard CO.
    Below is my code.
    processRequest(OAPageContext pageContext,OAWebBean webbean)
    super.processRequest(pageContext,webbean);
    processFormRequest(OAPageContext pageContext,OAWebBean webbean)
    super.processRequest(pageContext,webbean);
    String evt = pageContext.getParameter(OAWebBEanConstants.EVENT_PARAM);
    OAApplicationModule oaapplicationmodule = pageContext.getRootApplicationModule();
    OAViewObject vo = (OAViewObject)oaapplicationmodule.findViewObject("DisplaydetailsVO");
    if(vo!=null)
    vo.first();
    String fwk = pageContext.getParameter("Runid"); *// If i use this statement to call the attribute value then Error 1 i am getting*
    (or)
    String qaz = (String)vo.getCurrentRow().getAttribute("Runid") *// If i use this statement to call the attribute value then Error 2 i am getting*
    if(event.equals("GO")
    try
    CallableStatement callablestatement = (oracleCallableStatement)oaapplicationmodule.getOADBTransaction().createCallableStatement("begin purchase_po_wf.purchasing_vision_wf(:1); end;",1);
    callablestatement.execute();
    callablestatement.setString(1,fwk);
    callablestatement.setString(1,qaz);
    callablestatement.close();
    callablestatement.close();
    Catch(SQLException ex)
    Please suggest me which statement to use call the Attributes & VO . Please do let me know if anything is wrong in the code.
    I am getting the below errors :
    1. Cannot call the procedurejava.lang.sql.exception Method in & out parameters extends::1
    2. Java.lang.NullPointerException
    Can any one please help me out , to overcome this issue. Its bit urgent
    Thanks,
    Kalyan

    Hi Kalyan,
    So you want to get the value of DisplaydetailsVO.Runid attribute
    and then use it for calling a package?
    and the attribute is Runid or RunId
    you can put the below code to get all the attributename and its values in the VO.(change the VO, AM names according to your customizations)
    Then you can get what should be attributeName you should be using it, and I am not sure about your requirement, you might need to call before super.processFormRequest().
    Get all the attribute from a VO with Attribute Names in Custom CO
    OAApplicationModule rootAM = pageContext.getRootApplicationModule();
    OAApplicationModule apprAM = (OAApplicationModule)rootAM.findApplicationModule("AppraisalsAM");
    String offlineStatus = (String)apprAM.invokeMethod("getOfflineStatus",new Serializable[]{appraisalId+""});
    OAViewObject appraisalVO = (OAViewObject)apprAM.findViewObject("AppraisalVO");
    if(appraisalVO !=null)
    AppraisalVORowImpl appraisalVORow = (AppraisalVORowImpl) appraisalVO.first();
    if(appraisalVORow !=null)
    int attrCount = appraisalVO.getAttributeCount();
    writeLog("XXRBG",pageContext,"Attrbuute count "+attrCount);
    String[] attributeNames = appraisalVORow.getAttributeNames();
    for (int i = 0 ;i< attributeNames.length ;i++ )
    writeLog("XXRBG",pageContext," Name "+attributeNames[i] +" = "+appraisalVORow.getAttribute(i));
    Thanks,
    With regards,
    Kali.
    OSSi.

  • Why are these SQL Exceptions coming?

    I have developed a web based application in which I am experiencing two exceptions coming after a periodic time.
    1)Exception : java.sql.SQLException: ORA-01000: maximum open cursors exceeded
    2)Exception : java.sql.SQLException: The url cannot be null
    The applications works fine when the webserver is restarted. What can be the probable reasons for these exceptions?

    Wrong forum... JDBC Forum: http://forum.java.sun.com/forum.jsp?forum=48
    1)Exception : java.sql.SQLException: ORA-01000: maximum open cursors exceededYou are not closing ur statments / prepared statments / callable statments after use.
    e.g.
    Statement st = connection.createStatement();
    try
      //execute some qwerys / do some updates
    catch( SQLException sqe )
      //handle exception
    finally
      st.close();
    } 2)Exception : java.sql.SQLException: The url cannot be nullI am guessing that the URL is null... where is the exception occouring????

  • Sql exception :too few paprameters to update

    I am getting an sql exception in this query below.
    It says too few parameters :expected 1
    String query = "UPDATE INR SET " + month+ " = " + mnt+ " where (IT = '" + initial + "') AND (new = '" + later+ "' ) AND (number = '" + num + "' ) AND (code = '" + Id + "')";
    I am just passing 1 telling it to update month column with mnt .
    Thanks,

    Here is my code with JDBC connecting to an Access Table
    String data ="jdbc:odbc:MonthUpdateTable";
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");     
         Connection conn = DriverManager.getConnection(data, "", "");
         Statement st = conn.createStatement();
         String query = "UPDATE INR SET " + month+ " = " + mnt+ " where (IT = '" + initial + "') AND (new1 = '" + later+ "' ) AND (number = '" + num + "' ) AND (code = '" + Id + "')";
         System.out.println(query);
         st.executeUpdate(query);
         st.close();
              conn.close();
    catch(Exception e) {System.out.println("UpdateError: " + e.toString()
               + e.getMessage());}
    Thanks,

  • SQL exception involving column index

    Hi. When I try to access a database with my servlet I get this exception:
    Caught SQL Exception: java.sql.SQLException: Column Index out of range ( 0 > 178).
    All my columns I use in my SQL statement seems fine. Any ideas?

    Sorry sir, here is the rest of the code and the exact exception I get is what I already mentioned in my first posting, so. Hope this makes sense to you.
    try
         out.println("Thank you! The test has been completed.");              
         String filename = valuecook + ".html";
         Document document = new Document();
         HtmlWriter writer = HtmlWriter.getInstance(document,new FileOutputStream("C:/jakarta-tomcat-4.0.6/webapps/ROOT/" + filename));
         document.open();
                 catch (DocumentException de) {
              System.err.println(de.getMessage());
               catch (IOException ioe) {
              System.err.println(ioe.getMessage());
         catch (SQLException sqlEx)
            out.println("Caught SQL Exception: " + sqlEx.toString() + "<br>");
         // now close the statement and connection if they exist
          if (stmt != null)
             try
              stmt.close();
             catch (SQLException sqlEx)
              out.println("Could not close: " + sqlEx.toString() + "<br>");
         if (conn != null)
             try
              conn.close();
              catch (SQLException sqlEx)
                  out.println("Could not close: " + sqlEx.toString() + "<br>");

  • Invalid Descriptor Index (SQL exception)

    Hi Defts,
    im developing an application using swings, im getting an Invalid Descriptor Index (SQL exception). I have given my code below kindly help me out.
    private void formWindowActivated(java.awt.event.WindowEvent evt) {                                    
    // TODO add your handling code here:
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbc");
    Connection con = DriverManager.getConnection("jdbc:odbc:tourismdatasource", "sa", "");
    String sel= "select * from tab_places where place_ID=?";
    PreparedStatement ps=con.prepareStatement(sel);
    ps.setString(1, jTextField4.getText().toString().trim());
    ResultSet rs=ps.executeQuery();
    if(rs.next())
    jTextField1.setText(rs.getString("place_name").toString());
    jTextField2.setText(rs.getString("state").toString());
    jTextField3.setText(rs.getString("category").toString());
    jTextArea1.setText(rs.getString("place_des").toString());
    catch(SQLException se){JOptionPane.showMessageDialog(null, se.getMessage());}
    catch(ClassNotFoundException ce){JOptionPane.showMessageDialog(null, ce.getMessage());}
    }

    It would help to know what statement is throwing the exception. The stack trace tells you that.
    As a guess the "select *" is returning the columns in a specific order. You are not calling getString() in that order though.
    Or one of the getString() values is wrong.
    And get rid of the ToString() calls on the getString() methods - they are already strings.

Maybe you are looking for