SERIAL and SERIAL8 data types

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

Because 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 classes that are specific to HCL OneDB into your Java™ program to handle SERIAL and SERIAL8 columns. To do this, add the following import line to your Java program:
import com.informix.jdbc.*;
Use the getSerial() method after an INSERT statement to return the serial value that was automatically inserted into the SERIAL column of a table. Use the getSerial8() method after an INSERT statement to return the serial value that was automatically inserted into the SERIAL8 column of a table. The methods return 0 if any of the following conditions are true:
  • The last statement was not an INSERT statement.
  • The table being inserted into does not contain a SERIAL or SERIAL8 column.
  • The INSERT statement has not executed yet.

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 implementation of the Statement interface, which is specific to HCL OneDB. The following example shows how to perform the cast:
cmd = "insert into serialTable(i) values (100)";
stmt.executeUpdate(cmd);
System.out.println(cmd+"...okay");
int serialValue = ((IfmxStatement)stmt).getSerial();
System.out.println("serial value: " + serialValue);

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 HCL OneDB SERIAL and SERIAL8 data types, see the HCL OneDB Guide to SQL: Reference and the HCL OneDB Guide to SQL: Syntax.