8

Deleted JDBC dates in Java (java.sql package)

 3 years ago
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)

advertisements

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.

Related Articles

An equivalent of date in java.sql? (Is there a java.sql.datetime?)

So far, I have not found a clear answer to this. I'd like to know what the equivalent is for a SQL type DATETIME and the java type, using a PreparedStatement. I have found: http://www.java2s.com/Code/Java/Database-SQL-JDBC/StandardSQLDataTypeswithThe

How to compare objects with a date variable (Hibernate)? Java.util.Date vs. java.sql.Timestamp

Environment: MySql 5.6.14 Spring MVC Hibernate I'm having problems to check if 2 objects are equal, and the problem is caused by de variable Date. I'm using Hibernate and it seems to be the problem of Timestamp (nanoseconds) and Date(miliseconds). Wh

Using SQL in Java with the java.sql package

during a lecture my professor gave examples of several actions involving databases and the java.sql package. These examples were supposed to be uploaded online in a pdf file, but for some reason the names of all functions and class names aren't displ

error while converting from Java.Util.Date to Java.Sql.Date

Possible Duplicate: How to convert java.util.date to java.sql.date? I found error on my function, it shows error result after initializing the newInstance() method from DatatypeFactory df , I'm getting another error: java.lang.ClassCastException: jav

Time zones in SQL DATE vs java.sql.Date

I'm getting a bit confused by the behaviour of the SQL DATE data type vs. that of java.sql.Date. Take the following statement, for example: select cast(? as date) -- in most databases select cast(? as date) from dual -- in Oracle Let's prepare and ex

Java.sql.Date and java.sql.Time to org.joda.time.DateTime

As the question title says, I have java.sql.Date and java.sql.Time as input Now I want to convert them to a DateTime object, but since the getDay, getYear etc. methods are deprecated I can't figure out how to combine the two...Just see if this does t

What is the difference between com.microsoft.sqlserver.jdbc.SQLServerConnection and java.sql.Connection

I'm having a Maven Web Application on a Tomcat 8 connecting to a SQL Server 2012 Database. For logging purposes I wanted to use the getClientConnectionID. Due to the policies of Microsoft it's quite a pain to make their driver work with Maven (I know

String - & gt; java.util.Date - & gt; java.sql.Date (with timestamp)

Here is my problem: I have a user input a date like: 2012-12-24 (string) I concatenate a time to that string, and convert to java.util.Date My code looks like: String tempstartdate = startdte; //startdte is the string value from a txtfield tempstartd

When converting String to Date, the ambiguity appeared between java.util.Date and java.sql.Date

I am trying to get date as input from Date tag of HTML Birth Date <input type="date" name="dob"/> and accessing on jsp page by using String strDate = request.getParameter("dob"); but it returns in the format of string a

Get the current date in java.sql.Date format

I need to add the current date into a prepared statement of a JDBC call. I need to add the date in a format like yyyy/MM/dd. I've try with DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); Date date = new Date(); pstm.setDate(6, (java.

Converting a string date to java.sql.Date

I'm having an issue while trying to insert a date into an SQL server using Java: //final String input = "20120823151034"; final String input = "06282013143533"; final DateFormat df = new SimpleDateFormat("MMddyyyyHHmmss"); fi

Problem converting java.util.Date to java.sql.Timestamp

I'm trying to put a user provided date into an SQL database, and I have the following lines to process the string and convert it to a java.sql.Timestamp object. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd'T'hh:mm"); java.util.D

Merge java.util.date with java.sql.Time

I have an extensive DATE-TIME conversion class, but i came across a scenario that i cannot resolve: I have a java.util.date: Tue May 10 00:00:00 BST 2011 I have a java.sql.time: 03:58:44 I need to create a java.util.date: Tue May 10 03:58:44 BST 2011

add 1 month from the current date using java.sql.Date

Hello i have a problem with the result of java.sql.Date. This is my code with adding 1 week from current date Date kini = new Date(); java.sql.Date jadwalPengobatan = new java.sql.Date(kini.getTime()+7*24*60*60*1000); If current date is 2016-02-27, t

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK