课程: Learning JDBC

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Exception handling in JDBC

Exception handling in JDBC

- [Instructor] Now we've spent a little bit of time dealing with error handling, but I want to talk about it a little bit more in depth. So first of all, why have we gone through all of this work? Error handling in JDBC quite honestly can be a nightmare if you don't manage it. Everything is a SQLException, and you have to actually unpack the exception to see what the actual error code coming from the database is and what that means. The important part here is that this is not something to ignore. If you ignore SQLExceptions, you don't really have any flow control in your application when a SQLException happens. So let's talk a little bit about some common unpacking. One of the strategies you can use is to unpack SQLExceptions into your own named exceptions. So you could build a handler the way we did a simple logging handler to look at the error state and from that throw a very specific named exception. You definitely can and should log error codes and add common messaging, much like…

内容