-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How can I get specific database error codes? URGENT!
PostPosted: Tue Oct 11, 2005 11:11 am 
Newbie

Joined: Tue Oct 11, 2005 10:57 am
Posts: 13
Hi!

How can I get specific database error codes in Hibernate?

I alredy saw that exists some classes that can help me (like ErrorCodeConverter, SQLException), but I didn't found any example of how to use it...

Help me, please!!!

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 11:39 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
SQLException.extractError() gives vendors error code


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 3:01 pm 
Newbie

Joined: Tue Oct 11, 2005 10:57 am
Posts: 13
Thanks, Dennys.

I think that is SQLException.getErrorCode(). ;)

But this didn't resolve my problem, but the following code do! They only applies in exceptions of the type ConstraintViolationException.

Code:

import java.sql.SQLException;
import org.hibernate.exception.ConstraintViolationException;

/**
*
* @author Reinaldo de Oliveira Castro
*/
public abstract class SqlUtility {
   
    public final static String UNIQUE_VIOLATION = "23505";
   
    public static String getSQLState(ConstraintViolationException $cve) {
       
        Throwable[] errs = ((ConstraintViolationException) $cve).getThrowables();
       
        return ((SQLException) errs[errs.length - 1]).getSQLState();
       
    }
   
}



And in my Main program:

Code:

if (e instanceof ConstraintViolationException) {
               
    String SQLState = SqlUtility.getSQLState((ConstraintViolationException) e);
                       
    if ((SqlUtility.UNIQUE_VIOLATION).equals(SQLState))
        System.out.println("It works!!!");
               
}


Thanks again,

Reinaldo de Oliveira Castro.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.