6 Replies Latest reply on Jan 26, 2018 3:40 AM by m.ardito

    How to handle TeiidSQLException in jsp page

    m.ardito

      I'm trying to develop a simple jsp page, on a local wildfly/teiid instance, to query a remote wildfly/teiid instance.

       

      I am trying to manage a "no record found" exception with something like this (just test code):

       

      try {
          rs.first();
          out.println("record found");
      } catch (TeiidSQLException e) {
          out.println("record not found");
      }

       

      but instead of catching the exception, it throws:

       

      13:06:29,970 ERROR [io.undertow.request] (default task-2)  UT005023: Exception handling request to /jsptest4/test.jsp: javax.servlet.ServletException: org.teiid
      .jdbc.TeiidSQLException: ResultSet cursor is after the last row.

       

      Can someone point me to the best way to handle this?

        • 1. Re: How to handle TeiidSQLException in jsp page
          shawkins

          That looks odd. It probably means there is a class loading issue - if this is using embedded Teiid in WildFly it should be referencing the client module, not including another copy of the client jar.  Otherwise you can also switch to just catching SQLException.

          • 2. Re: How to handle TeiidSQLException in jsp page
            m.ardito

            I get the same error even with SQLException or Exception...

            it's not Teiid embedded, it's the wildfly/teiid bundle...

             

            I get the above error, if I import org.teiid.jdbc.*

            If I don't add org.teiid.jdbc.*, I get

             

            13:42:26,898 ERROR [io.undertow.request] (default task-7)  UT005023: Exception handling request to /jsptest4/test.jsp: org.apache.jasper.JasperException: JBWEB0
            04062: Unable to compile class for JSP:
            
            JBWEB004060: An error occurred at line: 72 in the jsp file: /test.jsp
            TeiidSQLException cannot be resolved to a type
            69:                    try {
            70:                            rs.first();
            71:                            out.println("record found");
            72:                    } catch (TeiidSQLException e) {
            73:                            out.println("record not found");
            74:                    }
            75:
            
            
            Stacktrace:
                    at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)

             

            ...?

            • 3. Re: How to handle TeiidSQLException in jsp page
              shawkins

              > I get the same error even with SQLException or Exception...

               

              That seems almost impossible.  Are you sure the exception is being emitted from where you think?

               

              > it's not Teiid embedded, it's the wildfly/teiid bundle...

               

              Sorry, I wasn't using proper terminology - if it's using a local, non-socket connection, then it should be using the same module as wildfly and not include a separate dependency.

               

               

              • 4. Re: How to handle TeiidSQLException in jsp page
                m.ardito

                Ok, I found the error (mine), you were right, is thrown by a later point...

                 

                reading better,

                ResultSet (Java Platform SE 8 )  says:

                Throws:
                SQLException - if a database access error occurs; this method is called on a closed result set or the result set type is TYPE_FORWARD_ONLY
                
                

                 

                ...of course if I have "no record found" it doesn't throw an exception... for that I have to try to fetch a field value, as

                 

                try {
                    
                    String fv = rs.getString("request");
                    
                    out.println("record found -");
                
                } catch (java.lang.Throwable t) {
                    if (!(t instanceof org.teiid.jdbc.TeiidSQLException)){
                        out.println("record not found - TeiidSQLException");
                    } else {
                        out.println("record not found - Generic");
                    }
                }       

                 

                 

                which throws (and catches) TeiidSQLException

                 

                or, better just check if there are records with something like

                 

                try {
                    rs.last();
                    size = rs.getRow();
                    rs.beforeFirst();
                    
                    out.println("record found -" +  size);
                
                }

                 

                and then manage the case where size == 0

                 

                Thanks...

                • 5. Re: How to handle TeiidSQLException in jsp page
                  shawkins

                  > and then manage the case where size == 0

                   

                  It seems like this logic will require you to have a scrollable result set which will add overhead.  If all you need to do is check for having a result, you would just check the boolean result of ResultSet.next().

                  • 6. Re: How to handle TeiidSQLException in jsp page
                    m.ardito

                    ...yes, right... I'm just digging into java again after years, to create in wildfly/teiid server a jasper reports report "lan distribution point" (just the library used by a jsp) to bring all the teiid power into paper , still have to grasp all the methods details... a bit confused... thanks...