Join David Gassner for an in-depth discussion in this video Handling JDBC exceptions, part of Java Database Integration with JDBC.
- View Offline
Just as with all Java programming, when something goes wrong in JDBC, you'll get an exception.…In JDBC, most methods of JDBC objects throw a class called SQLException.…SQLException is extended from the Exception class, and it inherits all of the tools that…are a part of that class, such as getMessage and getLocalizedMessage, string representations…of an error message, getStackTrace, and many other tools.…But JDBC is all about databases, and so its special exception class SQLException is specifically…designed to give you information about what's going on in the database.…
SQLException adds these methods, getErrorCode returns an integer value which tells you what might have gone wrong.…The Error code is unique to the particular database, so a numeric error code for MySQL…won't be the same as for HSQLDB, and so on.…And there's also a method called getSQLState which returns a five-character string.…It's just like the error code.…It's specific to the particular vendor and the particular database, but it's a string instead of an integer.…
Author David Gassner explains how to choose a JDBC driver and connect to one or more databases. He also provides detailed instructions on reading, selecting, and updating data; calling stored procedures; managing data via JavaBean classes or with prepared statements; and working with metadata.
- Importing a MySQL database
- Connecting to databases
- Handling JDBC exceptions
- Looping through result sets
- Limiting the number of fetched rows
- Filtering data with prepared statements
- Calling stored procedures
- Inserting, updating, and deleting rows with prepared statements
- Using a persistent database connection
- Committing and rolling back transactions