Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
904 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Expliquez moi les "Handler Exception"

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Expliquez moi les "Handler Exception"

n°1500543
Shogun2002
Posté le 08-01-2007 à 21:47:03  profilanswer
 

Bonjour
 
J'utilise une librairie qui gere la persistence.
Mais il se peut que la connexion se coupe (BD qui redemarre, réseau qui se coupe, etc ...) et genere une DatabaseException
Cette librairie me dit d'implementer la méthode oracle.toplink.exceptions.ExceptionHandler pour remedier à ce pb
Comme ceci :

Code :
  1. public class ExceptionHandler implements
  2. oracle.toplink.exceptions.ExceptionHandler
  3. {
  4. private static Log LOG = LogFactory.getLog(ExceptionHandler.class);
  5. /**
  6. * Called by Toplink to handle the exception
  7. *  
  8. * @see oracle.toplink.exceptions.ExceptionHandler#handleException(java.lang.RuntimeException)
  9. */
  10. public Object handleException(RuntimeException exception)
  11. {
  12. if (exception instanceof DatabaseException)
  13. {
  14. DatabaseException dbex = (DatabaseException) exception;
  15. LOG.info(" DatabaseException. Error Code: " + dbex.getErrorCode() +
  16. ". DB ErrorCode: " + dbex.getDatabaseErrorCode() +
  17. ". Message: " + dbex.getMessage());
  18. // 17410 - No more data to read from socket
  19. if (dbex.getDatabaseErrorCode() == 17410)
  20. {
  21. LOG.debug(" Found 17410: " + dbex.getErrorCode());
  22. dbex.getAccessor().reestablishConnection(dbex.getSession());
  23. return dbex.getSession().executeQuery(dbex.getQuery());
  24. }
  25. }
  26. // Handle all other exceptions by rethrowing  
  27. throw exception;
  28. }
  29. }


 
Heu ... Oui  :??:  
Mais je mets cette nouvelle classe ExceptionHandler où ?
Que dois-je configurer d'autres pour que cette exception qui essaie de se reconnecter puisse fonctionner ?
 
 
Merci de votre aide  :jap:


Message édité par Shogun2002 le 08-01-2007 à 21:49:58
mood
Publicité
Posté le 08-01-2007 à 21:47:03  profilanswer
 

n°1500552
Shogun2002
Posté le 08-01-2007 à 22:08:32  profilanswer
 

Si je comprends bien faut que je fasse ceci :
 

Code :
  1. class lanceRequete{
  2. public class ExceptionHandler implements oracle.toplink.exceptions.ExceptionHandler
  3. ...
  4. throw exception;
  5. }
  6. }
  7. try{
  8. //Code qui envoie requete SQL
  9. }
  10. catch(SQLException e){
  11. }
  12. }


 
 
????


Message édité par Shogun2002 le 08-01-2007 à 22:08:48

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Expliquez moi les "Handler Exception"

 

Sujets relatifs
[Batch] Créer une exception pour la commande DELThreading et exception?
Pb exception qui agassent!ASP.NET -> Memory Exception, introuvable j'en peut plus !
[mySQL] L'exception SocketException n'a pas été gérée ...[Résolu][C# .net] SqlDataReader ne contenant rien => exception
Exception in thread "main".java.lang.StringIndexOutOfBoundsException"Exception CSS" sur un lien
Exception JDOM incompréhensibleJava -> Date, probleme d exception ?!
Plus de sujets relatifs à : Expliquez moi les "Handler Exception"


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR