Java中不推荐使用的JDBC日期(java.sql软件包) [英] JDBC Dates Deprecated in Java (java.sql package)

查看:267
本文介绍了Java中不推荐使用的JDBC日期(java.sql软件包)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JDBC和MySQL.我的结果集中需要包含一个日期列.不幸的是,我找不到Java中的类来检索日期.不推荐使用SQL Date类.如何从结果集中获取Date对象?

解决方案

您使用 java.sql.Date .不建议使用构造函数和某些方法.这个班不是.将此与 java.util.Date java.util.Calendar ?请查看了解Java的日期. /p>

共有三种JDBC日期/时间类型:

混淆可能是由于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:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆