Is it possible to receive URL from DataAccessException in hibernate spring?
I use a spring hibernate framework and in catch for query update receive
For write in error log I would like receive URL of database, SQL error etc. Does it possible receive from DataAccessException type? Thanks.
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:
- Get SQL error via ex.getMessage();
- Get database URL from Hibernate session.
- 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.