slocke
Mar 3rd, 2006, 03:23 PM
I have a Query class that can return data based on a query. Initially, this was coded using java.sql.Resultset:
import java.sql.ResultSet;
public class QueryDAO extends JdbcDaoSupport {
public ResultSet loadResultSet(String sSQL)
{
ResultSet rset = null;
try{
Connection conn = getConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE, ResultSet.CONCUR_READ_ONLY);
rset = stmt.executeQuery(sSQL);
}
catch (java.sql.SQLException e){
e.printStackTrace();
}
return rset;
}
}
I recently switched from ResultSets to SqlRowSet, thusly:
import org.springframework.jdbc.support.rowset.SqlRowSet;
public class QueryDAO extends JdbcDaoSupport {
public SqlRowSet loadSqlRowSet(String sSQL)
{
return getJdbcTemplate().queryForRowSet(sSQL);
}
}
When I did so, I noticed that date fields that were in the ResultSet as java.sql.Timestamp are now being returned as java.sql.Date. The time aspect of the date fields are all being set to 0.
If I query the ResultSet metadata for the date field thusly:
System.out.println("Column Name " + rsmd.getColumnName(i) +
" ; ClassName " + rsmd.getColumnClassName(i) +
" ; Type " + rsmd.getColumnTypeName(i) + "\n");
I get this:
Column Name DISCHARGE_DATE_0 ; ClassName java.sql.Timestamp ; Type DATE
If I query the contents of the discharge_date field in WinSQL, I get this: "2000-07-08 08:05:00"
If I do a .getTimestamp() on the field, I get this: "2000-07-08 08:05:00.0" (seems to match what WinSQL produces).
Now, here's what SqlRowSet does:
If I query the SqlRowSet metadata, I get this:
Column NameDISCHARGE_DATE_0 ; ClassName java.sql.Date ; Type DATE
It is saying the field is a Date, not a Timestamp.
If I do a .getTimestamp() on the field, I get this: "2000-07-08 00:00:00.0"
You can see that the TIME precision has been lost.
Anyone know why SqlRowSet can't return full precision for date/time fields?
Thanks,
s.l.
import java.sql.ResultSet;
public class QueryDAO extends JdbcDaoSupport {
public ResultSet loadResultSet(String sSQL)
{
ResultSet rset = null;
try{
Connection conn = getConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE, ResultSet.CONCUR_READ_ONLY);
rset = stmt.executeQuery(sSQL);
}
catch (java.sql.SQLException e){
e.printStackTrace();
}
return rset;
}
}
I recently switched from ResultSets to SqlRowSet, thusly:
import org.springframework.jdbc.support.rowset.SqlRowSet;
public class QueryDAO extends JdbcDaoSupport {
public SqlRowSet loadSqlRowSet(String sSQL)
{
return getJdbcTemplate().queryForRowSet(sSQL);
}
}
When I did so, I noticed that date fields that were in the ResultSet as java.sql.Timestamp are now being returned as java.sql.Date. The time aspect of the date fields are all being set to 0.
If I query the ResultSet metadata for the date field thusly:
System.out.println("Column Name " + rsmd.getColumnName(i) +
" ; ClassName " + rsmd.getColumnClassName(i) +
" ; Type " + rsmd.getColumnTypeName(i) + "\n");
I get this:
Column Name DISCHARGE_DATE_0 ; ClassName java.sql.Timestamp ; Type DATE
If I query the contents of the discharge_date field in WinSQL, I get this: "2000-07-08 08:05:00"
If I do a .getTimestamp() on the field, I get this: "2000-07-08 08:05:00.0" (seems to match what WinSQL produces).
Now, here's what SqlRowSet does:
If I query the SqlRowSet metadata, I get this:
Column NameDISCHARGE_DATE_0 ; ClassName java.sql.Date ; Type DATE
It is saying the field is a Date, not a Timestamp.
If I do a .getTimestamp() on the field, I get this: "2000-07-08 00:00:00.0"
You can see that the TIME precision has been lost.
Anyone know why SqlRowSet can't return full precision for date/time fields?
Thanks,
s.l.