java.util.Date, java.util.Timetamp were seems to be causing great confusion for many. Within StackOverflow there are so many questions, Unfortunately my question is bit twisted.
There are 2 JDBC api. How they should perform? Was there any consistencies among RDBMS’es?
ResultSet.getTimestamp("dateColumn")
ResultSet.getTimestamp("dateColumn", Calendar.getInstance(tz))
If someone has knowledge in Sybase, could you please share your experience?
First, you’re confusing
java.utilwithjava.sql. When usingPreparedStatement#setDate()andResultSet#getDate(), you needjava.sql.Date. Analogous, when usingPreparedStatement#setTimestamp()andResultSet#getTimestamp()you needjava.sql.Timestamp.Second, it’s important to understand that
java.sql.Daterepresents solely the date (year, month, day) and nothing less or more. This is to be mapped to a SQLDATEfield type. Thejava.sql.Timestamprepresents the timestamp (year, month, day, hour, minute, second, millisecond), exactly as thejava.util.Dateandjava.util.Calendardoes. This is to be mapped to a SQLTIMESTAMPorDATETIMEfield type.As to the timezones, you need it when the database does not store timezone information (thus, all timestamps are stored in UTC (GMT)). You can then pass a
Calendarin which contains information about the current timezone, so that the JDBC driver can adjust the UTC timestamp to the timestamp conforming the timezone. If it is for example GMT+1, then the JDBC driver will add one hour to the timestamp before returning.