Home | Previous Page | Next Page   Internationalization and Date Formats > Support for DATE End-User Formats >

DBDATE Variable

Support for the DBDATE environment variable provides backward compatibility for client applications that are based on Informix database server versions prior to 7.2x, 8.x, or 9.x. You should use the GL_DATE environment variable for new applications.

The DBDATE environment variable specifies the end-user formats of values in DATE columns. End-user formats are used in the following ways:

With standard formats, you can specify the following attributes:

The format string can include the following characters:

The following format strings are valid standard DBDATE formats:

The separator always goes at the end of the format string (for example, DMY2/). If no separator or an invalid character is specified, the slash ( / ) character is the default.

For the U.S. ASCII English locale, the default setting for DBDATE is Y4MD-, where Y4 represents a four-digit year, M represents the month, D represents the day, and hyphen ( - ) is the separator (for example, 1998-10-08).

To insert a date value into a database table with a date column, you can perform the following types of inserts:

The following example shows both types of inserts (the DBDATE value is MDY2-):

stmt = conn.createStatement();
cmd = "create table tablename (col1 date, col2 varchar(20));";
rc = stmt.executeUpdate(cmd);..
.String[] dateVals = {"'08-10-98'", "{d '1998-08-11'}" };
String[] charVals = {"'08-10-98'", "'08-11-98'" };
int numRows = dateVals.length;
for (int i = 0; i < numRows; i++)
    {
    cmd = "insert into tablename values(" + dateVals[i] + ", " + 
        charVals[i] + ")";
    rc = stmt.executeUpdate(cmd);
    System.out.println("Insert: column col1 (date) = " + dateVals[i]);
    System.out.println("Insert: column col2 (varchar) = " + charVals[i]);
    } 

To retrieve the formatted DBDATE DATE value from the database, call the getString method of the ResultSet class.

To enter strings that represent dates into database table columns of char, varchar, or lvarchar type, you can build date objects that represent the date string value. The date string value needs to be in DBDATE format.

The following example shows both ways to select DATE values:

PreparedStatement pstmt = conn.prepareStatement("Select * from tablename "
    + "where col1 = ?;");
GregorianCalendar gc = new GregorianCalendar(1998, 7, 10);
java.sql.Date dateObj = new java.sql.Date(gc.getTime().getTime());
pstmt.setDate(1, dateObj);
ResultSet r = pstmt.executeQuery();
while(r.next())
    {
    String s = r.getString(1);
    java.sql.Date d = r.getDate(2);
    System.out.println("Select: column col1 (DBDATE format) = <" 
        + s + ">");
    System.out.println("Select: column col2 (JDBC Escape format) = <" 
        + d + ">");
    }
r.close();
pstmt.close();
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]