Have this method call:
-> simpleJdbcTemplate.queryForInt(SQL,null); ->
queryForInt()in sources SimpleJdbcTemplatecreates DataAccessExceptionwhich is an exception to the runtime. I want to propagate exceptions at the application presentation level, since working with Spring Spring Wraps Checked Exceptions inside RuntimeExceptionsI'm stuck here.
queryForInt()
SimpleJdbcTemplate
DataAccessException
RuntimeExceptions
How can I do it?
Explanation 1:
Additional benefits provided by the JDBC abstraction Spring Framework framework- say that the Spring Framework takes care of everything except 3 and 6. 3 and 6 should be written by the application developer.
Define Connection Settings
Open connection
Indicate statement
Prepare and execute an expression
Set up a loop to iterate over the results (if any)
Do the work for each iteration
, , . , . , ().
, ( , RuntimeException Error, RuntimeException Error ) unchecked exceptions (RuntimeException Errors Throwable).
, - :
try { //... processing } catch(Exception/RuntimeException e) { // propagate the exception to the view in a meaningful manner }
, - .
, Java, , , , :
try { //...spring code } catch(DataAccessException e) { throw new Exception(e); }
.
, Spring , , . - DataAccessExceptions, :
try { // query logic } catch (DataAccessException ex) { // handle the exception }
Spring MVC, , ExceptionResolver. , , . , , .
? , getCause() RuntimeException, , . "throws" , SimpleJdbcTemplate, DataAccessException , .
Source: https://habr.com/ru/post/1708366/More articles:What is the most elegant way to map one list to another in Java? - javaHow can I write a SELECT statement in which a condition is the result of a function - sqlSQL if (exists ()) duplicate queries - sqlCan I use JSTL to display a date in the clientβs time zone? - javaCan relative paths be used when using include libraries in the Flex mxmlc compiler? - flexHow can I find the size of a DataTable string in C #? - c #asp: controlling DataList with asp: LinkButton inside - something weird - asp.netVisual Studio Auto Copy File When Saving - .netNeed help with Eval inside DataList - asp.netHow can I implement multiple inheritance resources in Zend Acl? - phpAll Articles