If you mean Spring Framework, then
In your DaoImpl, throw the SQLException, pass it to controller via Model ( i guess you have done this already ). In controller catch the SQLexception. use
errors.reject ( "DB Error", new Object[] { new Integer ( sqlException.getErrorCode() ) , sqlException.getCause().getMessage()}, "DB Error: {0} : {1}" );
you can set this in your messages.properties also.