Deleted JDBC dates in Java (java.sql package)
source link: https://www.codesd.com/item/deleted-jdbc-dates-in-java-java-sql-package.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Deleted JDBC dates in Java (java.sql package)
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.
Related Articles
An equivalent of date in java.sql? (Is there a java.sql.datetime?)
How to compare objects with a date variable (Hibernate)? Java.util.Date vs. java.sql.Timestamp
Using SQL in Java with the java.sql package
error while converting from Java.Util.Date to Java.Sql.Date
Time zones in SQL DATE vs java.sql.Date
Java.sql.Date and java.sql.Time to org.joda.time.DateTime
What is the difference between com.microsoft.sqlserver.jdbc.SQLServerConnection and java.sql.Connection
String - & gt; java.util.Date - & gt; java.sql.Date (with timestamp)
When converting String to Date, the ambiguity appeared between java.util.Date and java.sql.Date
Get the current date in java.sql.Date format
Converting a string date to java.sql.Date
Problem converting java.util.Date to java.sql.Timestamp
Merge java.util.date with java.sql.Time
add 1 month from the current date using java.sql.Date
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK