Hi Michael,

I tried do that but pbx.getCause() is not PersistenceBrokerSQLException.
pbx.getSourceException() is instance of SQLException and the cause is
"Duplicate entry 'xxxxxx' for key2". I can use this message to do exception
handling. However, I was wandering if it is a generic way to find the
details of SQLException?
Thanks.

Leon
----- Original Message -----
From: "Michael Hart" <[EMAIL PROTECTED]>
To: "'OJB Users List'" <[EMAIL PROTECTED]>
Sent: Tuesday, May 27, 2003 9:02 PM
Subject: RE: How to handle SQLException in OJB?


> Hi Leon,
>
> It looks like you're logging level is not set correctly - you need to set
> the logging level of JdbcAccessImpl to FATAL because the printStackTrace
> occurs when set to ERROR or below.
>
> If you're using the default logger (PoorMansLoggerImpl), then you want to
> change your logging levels in OJB.properties:
>
> # Note that this is NOT JdbcAccess, but rather JdbcAccessImpl
> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.LogLevel=FATAL
>
>
> After this, you can catch a PersistenceBrokerException and check whether
it
> is an SQL exception or not:
>
> try
> {
>     Collection allProducts = broker.getCollectionByQuery(query);
> }
> catch (PersistenceBrokerException pbx)
> {
>     // The PersistenceBrokerSQLException is nested in pbx and the
>     // SQLException is nested in that (ie pbx.getCause().getCause())
>     if (pbx.getCause() instanceof PersistenceBrokerSQLException) {
>         System.out.println("SQL problem " + pbx.getCause());
>     }
> }
>
> Cheers,
>
> Michael
>
> -----Original Message-----
> From: Leon [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, 28 May 2003 1:38 AM
> To: OJB Users List
> Subject: Re: How to handle SQLException in OJB?
>
> Here is it. I am using PersistenceBroker.
>
> Thanks.
>
> .......
>
> tx.begin();
>
> broker.store(registryvo);
>
> tx.commit();
>
> } catch (SQLException e) {
>
> e.printStackTrace();
>
> } catch (PersistenceBrokerException e) {
>
> if (log.isEnabledFor(Priority.INFO)) {
>
> log.info(
>
> "********* Something went wrong while insert a record to account
> **********");
>
> }
>
> e.printStackTrace();
>
> throw new DataAccessException("Error in RegistryDAO.insert():" +
>
> e.toString(), e);
>
> }
>
> ----- Original Message -----
> From: "Michael Hart" <[EMAIL PROTECTED]>
> To: "'OJB Users List'" <[EMAIL PROTECTED]>
> Sent: Tuesday, May 27, 2003 11:12 AM
> Subject: RE: How to handle SQLException in OJB?
>
>
> > > I already tried that but it is unreachable catch block.
> >
> > It could be from the logger - have you disabled output from that? (or at
> > least set the log-level to something high-ish)
> >
> > The default logger (PoorMansLoggerImpl) will print a stack trace if a
> > Throwable is logged (perhaps log4j does as well), so this may be your
> > problem.
> >
> > Which code is causing the problem? Can you give a sample? Are you using
> > PersistenceBroker or ODMG or JDO?
> >
> > Cheers,
> >
> > Michael
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to