Display specific error! java.sql.SQLException '

0

Hello

I'm like the following code:

<c:set var="exception" value="${requestScope['java.sql.SQLException']}"/>
    <p class="alert alert-danger"><b>Ops!</b> Erro: <br><br>
 <!-- Stack trace -->

    <jsp:scriptlet>
      // exception.printStackTrace();
      exception.printStackTrace(new java.io.PrintWriter(out));
    </jsp:scriptlet>
   </p>

Only the error comes a lot:

 java.sql.SQLException: ORA-20999: Aluno já cadastrado anteriormente
 ORA-06512: em "DBAADV.TRG_CURSO_INSCRICAO", line 8 
 ORA-04088: erro durante a execução do gatilho 'DBAADV.TRG_CURSO_INSCRICAO' 
 ORA-06512: em "DBAADV.PROC_INSCRICAO", line 13 
 ORA-06512: em line 1 at 
 oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) at 
 oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399) at 
 oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059) at 
 oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522) at 
 oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257) at 
 oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587) at 

I would just like to get the specific error:

ORA-20999: Aluno já cadastrado anteriormente

or

Aluno já cadastrado anteriormente

My try / catch

try {
             ...           
        } catch (SQLException ex) {
            throw new ServletException(ex);

        }
    
asked by anonymous 17.05.2017 / 14:48

1 answer

0

The console is showing a lot of information because you are viewing the entire stacktrace of the exception.

Instead, what you are looking for is the detailed message of the exception, which can be accessed through getMessage() or getLocalizedMessage() if you want the error message to be located.

The error code (ORA-2099 in your example) can also be obtained through getSQLState() .

My biggest doubt (especially reading the comments) and the edited question is because you want to print exception information through your JSP page. The content of the JSP should, in general, consist only of elements that will compose what is processed in the clients.

Treating the exception you want to see is part of the server scope, and it would be much easier to include it next to your catch through a System.out.println() passing as a parameter the message / cause / code and any other details of the exception that interest you, or better yet: use your Logger to print according to your l4j settings.

    
17.05.2017 / 15:46