users@glassfish.java.net

capture "com.mysql.jdbc.exceptions"

From: <glassfish_at_javadesktop.org>
Date: Sun, 06 Jan 2008 01:01:10 PST

Hi all,
I have this Session Bean that call a Facade method, in order to create entries in a table.

@Stateless(mappedName = "ejb/businessobjs/admin/CreateProductBOBean")
public class CreateProductBOBean implements CreateProductBORemote {

    @EJB(mappedName = "ejb/facades/ProductsFacade")
    private ProductsFacadeLocal productsFacade;

    public int CreateProduct(String Description, String Code) throws Exception{

        try {

            Products pr = new Products();
            pr.setDescription(Description);
            pr.setCode(Code);
            productsFacade.create(pr);

            return(0);
            
        } catch (Exception e) {
            return(1);
        }
        
    }
}

How can I catch a "com.mysql.jdbc.exceptions.*", that could arise for instance during a duplicate entry insertion ?

I mean the glassfish output return this:

Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '001' for key 2
Error Code: 1062
[...]

but the code don't mind regarding it even if I've declared the Session Bean throwable.

Thanks in advance.
s1
[Message sent by forum member 's1a2' (s1a2)]

http://forums.java.net/jive/thread.jspa?messageID=252392