开发者

How do you get both date and time from a PreparedStatement in Java?

I am currently using SELECT datetime FROM table1 WHE开发者_JAVA技巧RE condition=? as the query and getting the ResultSet object, and I am using rs.getDate() and it is creating a Date object with no Time as part of it. Is it possible to get both the Date and the Time from the database?


getTimestamp() should fetch you both the "date" and "time" part. Read the docs for java.sql.Date (which is returned by getDate and java.sql.Timestamp for knowing the difference between them.


If you are trying to get the date stored in one of the columns of the resultset obtained from the database, then you can use the rs.getDate(columnIndex) method. You have to specify the index of the column which contains the date. suppose your table is like this:

ID | name | date|

then you will have to use rs.getDate(3) [or may be getDate(2), I am not sure if the column index starts from 0 or 1 ]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜