Java Reference
In-Depth Information
CREATE TYPE EMPLOYEE
(
EMP_ID INTEGER,
LAST_NAME VARCHAR(40),
FIRST_NAME VARCHAR(40),
RESIDENCE ADDRESS,
SOCIAL SSN
);
This definition can be created in a JDBC application by opening a connection and
creating a Statement in the normal way, then executing the following code to send the
definition of the structured type EMPLOYEE to the database.
String createEmployee = "CREATE TYPE EMPLOYEE ("+
"EMP_ID INTEGER,"+
"LAST_NAME VARCHAR(40),"+
"FIRST_NAME VARCHAR(40),"+
"RESIDENCE ADDRESS,"+
"SOCIAL SSN);";
stmt.executeUpdate(createEmployee);
On occasion, your code may generate errors. Java handles these errors by throwing
SQLExceptions, as discussed in the next section .
Exceptions and Logging
There are several types of exceptions which can be thrown during data base access.
The most common is the SQLException.
SQLException
The SQLException class extends java.lang.Exception to provide information on
database-access errors. Each SQLException provides the following information:
 
The Java exception message String, available using the getMessage() method
 
The SQLState String, which follows the XOPEN SQLState conventions, available using the
getSQLState() method
 
A vendor-specific, integer-error code, available using the getErrorCode() method. Normally, this
isthe actual error code that the underlying database returns.
SQLException also lets you get the next exception, which can be used to provide
additional error information.
SQLWarning
Search WWH ::




Custom Search