In JDBC, errors and exceptions are identified by the java.sql.SQLException class (which extends the java.lang.Exception class).
SQLException is a checked exception. There are two types of exceptions in Java: checked and unchecked, or runtime, exceptions. A checked exception is a subclass of java.lang.Throwable (the Throwable class is the superclass of all errors and exceptions in the Java language) but not of RunTimeException (RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java VM). Checked exceptions have to be caught (and handled properly) or appear in a method that specifies in its signature that it throws that kind of exception. When a JDBC object (such as Connection, Statement, or ResultSet) encounters a serious error, it throws a SQLException. For example, an invalid database URL, an invalid database username or password, database connection errors, malformed SQL statements, an attempt to access a nonexistent table or view, and insufficient database privileges all throw SQLException objects. The client(the database application program) accessing a database server needs to be aware of any errors returned from the server. JDBC give access to such information by providing several levels of error conditions:
The SQLException class extends the java.lang.Exception class and defines an additional method called getNextException(). This allows JDBC classes to chain a series of SQLException objects together. In addition, the SQLException class defines the getMessage(), getSQLState(), and getErrorCode() methods to provide additional information about an error or exception. In general, a JDBC client application might have a catch block that looks something like this:
To understand transaction management, you need to understand the Connection.setAutoCommit() method. Its signature is void setAutoCommit(boolean autoCommit) throws SQLException According to J2SE 1.5, setAutoCommit() sets this connection’s autocommit mode to the given state. If a connection is in autocommit mode, then all its SQL statements will be executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either the commit() or the rollback() method. By default, new connections are in autocommit mode. The following example shows how to handle commit() and rollback() when an exceptionhappens:
In the following example we force the exception to happen: instead of VARCHAR(when creating the cats_tricks table), we type VARZCHAR (the database server will not understand VARZCHAR and therefore it will throw an exception):
|
|
Jdbc Tutorial
What Is Jdbc Programming?
Database Metadata, Part 1
Database Metadata, Part 2
Resultset Metadata
Parameter Metadata
Exploring Driver Property Information
Rowset Metadata A
Web Access To Metadata,part 1
Web Access To Metadata, Part 2
Rdf And Jdbc Metadata
Text Resumes
Visual Resumes
Social Resumes
Resume Quality
IT Resume Samples
MARKETING Resume Samples
HR Resume Samples
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.