informix
Informix JDBC Driver Programmer's Guide
Manipulating Informix Data Types

Manipulating Informix SERIAL and SERIAL8 Data Types

Informix JDBC Driver provides support for the Informix SERIAL and SERIAL8 data types via the methods getSerial() and getSerial8(), which are part of the implementation of the java.sql.Statement interface.

Since the SERIAL and SERIAL8 data types do not have an obvious mapping to any JDBC API data types from the java.sql.Types class, you must import Informix-specific classes into your Java program to be able to handle SERIAL and SERIAL8 table columns. To do this, add the following import line to your Java program:

Use the getSerial() and getSerial8() methods after an INSERT statement to return the serial value that was automatically inserted into the SERIAL or SERIAL8 column of a table, respectively. The methods return 0 if any of the following conditions are true:

If you execute the getSerial() or getSerial8() method after a CREATE TABLE statement, the method returns 1 by default (assuming the new table includes a SERIAL or SERIAL8 column). If the table does not contain a SERIAL or SERIAL8 column, the method returns 0. If you assign a new serial starting number, the method returns that number.

If you want to use the getSerial() and getSerial8() methods, you must cast the Statement or PreparedStatement object to IfmxStatement, the Informix-specific implementation of the Statement interface. The following example shows how to perform the cast:

If you want to insert consecutive serial values into a column of data type SERIAL or SERIAL8, specify a value of 0 for the SERIAL or SERIAL8 column in the INSERT statement. When the column is set to 0, the database server assigns the next-highest value.

For more detailed information about the Informix SERIAL and SERIAL8 data types, refer to Informix Guide to SQL: Reference and Informix Guide to SQL: Syntax. You can find the on-line version of both of these guides at http://www.informix.com/answers.


Informix JDBC Driver Programmer's Guide, Version 2.0
Copyright © 1999, Informix Software, Inc. All rights reserved