We'll handle the errors for you - and we're not telling you how
I'm trying to use Spring-JDBC for data access, and whilst it's great not to have to deal with connection pools and JBCD drivers, I can't find it documented anywhere what I'll actually get back if an unrecoverable error occurs under the hood of one of their abstractions.
Specifically, I'm using SimpleJdbcCall to call stored procedures in a database.
SimpleJdbcCall call = new SimpleJdbcCall() .withProcedureName("SP_DO_STUFF") .returningResultSet("results", new MyRowMapper()); SqlParameterSource inParams = new MapSqlParameterSource() .addValue("inputParam", "foo"); Map<String, Object> returnedData = call.execute(inParams); MyClass results = (MyClass) returnedData.get("results");
What happens if there's an error in the database?
call.execute(...)doesn't throw any checked exceptions. Do I get an empty map? Or null? Or a runtime exception of some sort? Why does it not say this anywhere? Please help me, I need to finish this by last week.
I'm trying to produce a webservice. Any DB errors are probably unrecoverable (or at least I don't have time to work out how to recover from them and for now it's not a must-have), but I do need to catch them and return a user-friendly error.
I have NFC about anything in Spring-JDBC (Sounds like a Java thing), but their documentation suggests that "All translated exceptions are unchecked, which gives you the option of catching the exceptions from which you can recover while allowing other exceptions to be propagated to the caller".
Assuming this is written from the point of view of the adapter, that means you're supposed to handle generic exceptions I guess?
Also see here a SO post I randomly found:
Snipped, in case proxy blocked:
@Tsaukpaetra Thank you! I don't know why I failed to find that. Looks like all DB errors turn up as some subclass of DataAccessException, so I can catch that. I was taught never to catch runtime exceptions but at least that beats catching Exception which I was seriously considering doing.
You are a lifesaver. Possibly literally, since if I don't get this finished tomorrow I will probably have a complete breakdown and not have to finish it because I'll have been wheeled away by one emergency service or other.
blakeyrat last edited by
@CarrieVS It can't be that important.
It can't be that important.
No. but I have anxiety issues.
blakeyrat last edited by
@CarrieVS I have the opposite.