Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    sql exception handling in SmartGWT

    I am trying to catch SQL Expection. whats the best way to do that?

    Shall I use try and catch block?

    try{
    DataSource dataSource1 = DataSource.get(DataSourceProperties.SSO_CLIENT_DATA_SOURCE);
    DSRequest dsUserRequest = new DSRequest();
    dsUserRequest.setOperationId(DataSourceProperties.RETRIEVE_CLIENT_ID);
    dataSource1.fetchData(createCriteria(StringClientDefinitions.CLIENT_CODE, getStrIataCode()),

    new DSCallback() {
    @Override
    public void execute(DSResponse dsResponse, Object o, DSRequest dsRequest) {
    getClientID(dsResponse, eventBus, appLayout);
    thumbNailNavigator(eventBus);
    }
    }, dsUserRequest);

    } catch(Exception e)
    {
    String msg = e.getMessage();
    }

    I am running above code when the database is down, it's throwing error before entering to catch statement.
    Basically i want to catch a error when DB goes down.

    Can you please suggest a way to catch it?
    Attached Files

    #2
    Exceptions that occur on the server cannot be "caught" by client-side code using catch() blocks. You need to either catch such an exception server-side, or use the error handling approaches explained here.

    Comment


      #3
      sql exception handling in SmartGWT

      Thanks for the responce. I have used below code and it works fine.
      DSRequest properties = new DSRequest();
      properties.setWillHandleError(true);
      listGrid.fetchData(new Criteria(), new DSCallback() {
      public void execute(DSResponse response, Object rawData, DSRequest request) {
      if (response.getStatus() < 0) {
      // Error handling here
      } else {
      // Normal processing here
      }
      }
      }, properties);

      response.getStatus() will give me a nagative number.

      I am getting "-1" as status for DB is down and also if the query is not appropriate.

      Is there way I can distinguish the error?

      I noticed that, dsResponse.getAttribute("data")
      is giving different error message,

      when DB is down I got "IO exception:Unknown Host specified".

      and when DB was up and running and SQL query waS breaking i got error as "ORA -00904: "TableName.Columname" invalid indetifier".

      Is there way I can handle this error?

      I want to do differnt operation when DB is down and when the query is breaking in few scenarios.

      Basiaclly when DB is down I will be showing a maintance issue and contact helpdesk. where as when Query fails we will be showing report problem.

      Comment


        #4
        There isn't really a standardized way for the JDBC driver to communicate this distinction when throwing an exception. You could either use the error message to figure out the distinction (be sure to make this configurable in your application in case Oracle changes the message in the future) or, after getting an error, you could execute a known working query like "select 1 from dual" to check for a connection problem.

        Comment

        Working...
        X