Timestamp string format in Informix JDBC format

I have an Informix database with a timestamp field defined as YEAR TO SECOND. When I display this field using JDBC rs.getString (column) it uses the format with miliseconds, so this field looks like this:

2008-12-18 13:58:14.0

      

I would like it to only use YEAR TO SECOND fields. I set my environment variable:

GL_DATETIME=%Y-%m-%D %H:%M:%S

      

but even then I got milliseconds. ODBC programs do not show milisecond. How can I get just the TIMESTAMP string "SECOND YEAR"? In my program, I can check the metadata if the field is TIMESTAMP and then strip ".0", but I think there should be an easier way.

Server version: IBM Informix Dynamic Server version 11.50.TC2DE

Client version: IBM Informix JDBC Driver for IBM Informix Dynamic Server 3.50.JC3DE

EDIT It looks like all the other JDBC drivers I have tested (Oracle and PostgreSQL) show Timestamp columns with miliseconds if I use getString (). So I used the solution provided by Todd. I check the metadata and if the column is Timestamp then I use getTimestamp () and format it.

+1


source to share


1 answer


If you are using JDBC, you can use the rs.getDate (column) or rs.getTimestamp (column) methods, which return Date and Timestamp objects respectively. Then you have an object representing the time, not a string expressing it directly. With Date or Timestamp, you can use the date format to format it for any string representation of the time you choose.



Update (after reading the comments below): If you use getDate () it will still work for Timestamp columns. It will simply reduce the accuracy to second. This way you don't need to validate the metadata, you just need to know that the column is some kind of timestamp or date.

+3


source







All Articles