Have this method call:
->
simpleJdbcTemplate.queryForInt(SQL,null);
->
queryForInt() method in the springs SimpleJdbcTemplate throws a DataAccessException which is a runtime exception. I want to propegate exceptions to the view tier of the application since Spring frame work Wraps Checked Exceptions inside RuntimeExceptions I stuck here.
How do I do this?
Explanation 1:
The value-add provided by the Spring Framework’s JDBC abstraction framework- they say The Spring Framework takes care of all except 3 and 6. 3 and 6 need to be coded by an application developer
-
Define connection parameters
-
Open the connection
-
Specify the statement
-
Prepare and execute the statement
-
Set up the loop to iterate through the results (if any)
-
Do the work for each iteration
-
Process any exception
-
Handle transactions
-
Close the connection
But if I encounter a situation where the connection to the database losses after certain time the program started. Then a runtime exception will be thrown when a call to the above method made.since I don’t handle the exception I cannot inform the user interface (view).
It depends if your view tier catches checked exceptions (any subclass of throwable that does not subclass RuntimeException or Error, or are not instances of RuntimeException or Error directly) or unchecked exceptions (RuntimeException or Errors or subclasses of these Throwable subclasses).
Generally, you’ll either have something like this:
If this is the case, for a runtime exception, you don’t have to do anything – the block will catch the runtime exception.
If you want to convert it to checked, assuming you’re using a version of Java that supports wrapped exceptions, all you have to do is:
Then, your layer above this processing will catch it as a checked exception.