Is it possible to receive URL from DataAccessException in hibernate spring?

I use a spring hibernate framework and in catch for query update receive

DataAccessException

For write in error log I would like receive URL of database, SQL error etc. Does it possible receive from DataAccessException type? Thanks.

Answers


There are sources of DataAccessException, where all the methods are defined, it is simply just a wrapper over Exception, so there is nothing much to see. Take into consideration, that it is not the only exception which database may throw, you should look for other exceptions, such as JDBCException.

The things you need can still be retrieved:

  1. Get SQL error via ex.getMessage();
  2. Get database URL from Hibernate session.
  3. Show real query SQL using Hibernate.

A DataAccessException does not always brings a SQLException.

You can't access the database informations from the Exception. You can have these informations from your Datasource.

Depending on your driver, you can get the SQLException wrapped into the DataAccessException. But it's not always the case.

Do not forget that an Exception is a wrapper of a problem. It does not contains information concerning the environment.


Need Your Help

Headless automation of a router login/restart is failing on the server but working locally using CasperJS

javascript networking phantomjs casperjs browser-automation

I have a script that works from Bash and CasperJS which constantly pings my servers. If all servers are down, the modem is restarted using a CasperJS script. From experience, when the issue occurs,