Steve,

If you are using BMP i.e. writing DB access code yourself,
you can catch the SQLException when performing an insert
and then retrieve (database) vendor specific error codes
which can be returned to the client 'wrapped' in another
user exception i.e. an application exception. But this is
of course database vendor dependent. If you switch DB vendors,
you would obviously need to rewrite your exception handling
code as well.

If you use CMP, then you would receive a CreateException.
You could parse this exception as it usually contains the
reason for the exception as a string (which will in turn
usually contain the error code or violation raised by
the database). Then again, the format of this string depends
on your jdbc driver as well as your db vendor. Switching
either (or both) will probably break your exception handling
code i.e. exception parser code.

In an earlier j2ee project I worked on, we used CMP and parsed
the exception to check if it was a SQLException and if it was
one, we further parsed it to pinpoint the exact cause (deadlock/
constraint violation etc). Of course the parser logic was dependent
on the jdbc driver and the db vendor itself. We used the session
facade pattern and the session bean did the above and then returned
an application exception to the client which contained an
error code and reason - which was usually enough for the
client in our case. I would not recommend throwing SQLExceptions.
They are too 'low level' IMO.

-krish

-----Original Message-----
From: A mailing list for Enterprise JavaBeans development 
[mailto:[EMAIL PROTECTED]]On Behalf Of Steve Brown
Sent: Monday, October 22, 2001 2:07 PM
To: [EMAIL PROTECTED]
Subject: SQLCodes from Entity Beans


Hi,

I am working on a project that converts an existing system to a j2ee equivalent.  The 
existing system has particular behaviour
depending on the SQL Code of SQL errors received during an INSERT statement.  ie if 
the SQLCode represents a deadlock then give a
message to "please try again" otherwise give them an error.

What is the best way to mimic this with entity beans?  Is it possible?  is it good 
form (or possible) to throw a SQLException from
an entity bean as well as a CreateException?

Thanks for any ideas,

Steve.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to