Java中不推荐使用的JDBC日期(java.sql软件包) [英] JDBC Dates Deprecated in Java (java.sql package)
问题描述
我正在使用JDBC和MySQL.我的结果集中需要包含一个日期列.不幸的是,我找不到Java中的类来检索日期.不推荐使用SQL Date类.如何从结果集中获取Date对象?
您使用 java.sql.Date .不建议使用构造函数和某些方法.这个班不是.将此与 java.util.Date 或 java.util.Calendar ?请查看了解Java的日期. /p>
共有三种JDBC日期/时间类型:
- 日期:天,请使用 java.sql.Date ;
- 时间戳:日期和时间,使用 java.sql.Timestamp ;
- 时间,没有日期的时间,请使用 java.sql.Time .
混淆可能是由于java.sql.Date扩展了java.util.Date并因此继承了其过时的方法.
只需为列的类型使用正确的类型即可.
I am working with JDBC and MySQL. I have a date column that I need included in my result set. Unfortunately, I cannot find a class in Java to retrieve the date. The SQL Date class is deprecated. How do you get Date objects from a result set?
You use java.sql.Date. A constructor and some methods are deprecated. The class isn't. Confused by this versus, say, java.util.Date or java.util.Calendar? Look at Making Sense of Java's Dates.
There are three JDBC date/time types:
- DATE: granularity of days, use java.sql.Date;
- TIMESTAMP: date and time, use java.sql.Timestamp;
- TIME, just the time with no date, use java.sql.Time.
The confusion probably arises from the fact that java.sql.Date extends java.util.Date and thus inherits its deprecated methods.
Just use the right type for the type of your column.
这篇关于Java中不推荐使用的JDBC日期(java.sql软件包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!