Tratar mensagem de erro do banco de dados para o usuario

Iniciado por nlsouza, 11 de Junho de 2011, 13:09

tópico anterior - próximo tópico

nlsouza

Colegas,
baixo o meu codigo. Como faço para mostrar uma mensagem bem formatada para ao usuário, quando a senha ou login estiverem errados?

Minha procedure

CREATE OR ALTER PROCEDURE SP_VALIDA_USUARIO (
   PLOGIN DM_LOGIN,
   PSENHA DM_SENHA )

AS
DECLARE VARIABLE vCOUNT DM_INTEIRO;
BEGIN  
   
   IF (NOT EXISTS(SELECT LOGIN FROM USUARIO WHERE LOWER(LOGIN) = LOWER(:PLOGIN))) THEN
       
       exception e_login;
     
   ELSE IF (NOT EXISTS (SELECT SENHA FROM USUARIO WHERE LOWER(LOGIN) = LOWER(:PLOGIN) and
                                                   LOWER(SENHA) = LOWER(:PSENHA)))THEN
   
       exception e_senha;
     
END

------------------

MEU METODO CHAMANDO A PROCEDURE:

public void validaUsuarioLogin(String strLogin, String strSenha) {
     
           String query = "{ call SP_VALIDA_USUARIO(?,?) }";
       try {
           executePrepered(query,strLogin,strSenha);
       } catch (SQLException ex) {            
           
           Logger.getLogger(UsuarioDao.class.getName()).log(Level.SEVERE, null, ex);    
     
       
       }        
         
     }  

-----------------------
MEU CODIGO NO BOTÃO ACESSAR DO FORMULARIO


private void btnAcessarActionPerformed(java.awt.event.ActionEvent evt) {                                          
       // TODO add your handling code here:
       
           dao.validaUsuarioLogin(txtUsuario.getText(), txtSenha.getText());
         
           setVisible(false);
           new frmPrincipal().setVisible(true);
   }      
             

----------------------------
MEU STACK TRACE NO NETBEANS:


11/06/2011 12:37:40 treinamento.forms.frmLogin btnAcessarActionPerformed
GRAVE: null
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544517. exception 5
E_SENHA
Senha inexistente
At procedure 'SP_VALIDA_USUARIO' line: 17, col: 84
at org.firebirdsql.jdbc.AbstractPreparedStatement.internalExecute(AbstractPreparedStatement.java:730)
at org.firebirdsql.jdbc.AbstractCallableStatement.internalExecute(AbstractCallableStatement.java:435)
at org.firebirdsql.jdbc.AbstractCallableStatement.executeUpdate(AbstractCallableStatement.java:341)
at treinamento.dao.GenericaDao.executePrepered(GenericaDao.java:72)
at treinamento.dao.UsuarioDao.validaUsuarioLogin(UsuarioDao.java:30)
at treinamento.forms.frmLogin.btnAcessarActionPerformed(frmLogin.java:165)
at treinamento.forms.frmLogin.access$000(frmLogin.java:23)
at treinamento.forms.frmLogin$1.actionPerformed(frmLogin.java:59)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6289)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6054)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4652)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:603)
at java.awt.EventQueue$1.run(EventQueue.java:601)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:617)
at java.awt.EventQueue$2.run(EventQueue.java:615)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Tota

Ola

Ao postar voce leu e aceitou a regra II de postagem

Se desejar, refaça seu topico dentro das regras

[]'s