You can do it the same way as a java.util.Date (since java.sql.Date is a sub-class of java.util.Date) with a SimpleDateFormat

SimpleDateFormat sdf = new SimpleDateFormat(
    "MM-dd-yyyy");
int year = 2014;
int month = 10;
int day = 31;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1); // <-- months start
                                    // at 0.
cal.set(Calendar.DAY_OF_MONTH, day);

java.sql.Date date = new java.sql.Date(cal.getTimeInMillis());
System.out.println(sdf.format(date));

Output is the expected

10-31-2014

Answer from Elliott Frisch on Stack Overflow
🌐
Coderanch
coderanch.com › t › 775227 › java › Datetime-format-sql-server
Datetime format for sql server (Beginning Java forum at Coderanch)
July 7, 2023 - Is there a already existing class ...686436900) to look like the DATETIME format (DATETIME - format: YYYY-MM-DD HH:MI:SS) ? Basically something like : 2005-07-30 23:59:59.000 ... There must be; you can doubtless change the java.sql.Date object to a LocalDate....
Discussions

datetime - How to format a java.sql Timestamp for displaying? - Stack Overflow
How do I formate a java.sql Timestamp to my liking ? ( to a string, for display purposes) More on stackoverflow.com
🌐 stackoverflow.com
jsp - how can i format the java.sql.Date to MM/dd/yyyy - Stack Overflow
As far as "date differences" in ... As far as "date formatting", just use SimpleDateFormat. ... Please don't ever assume there are exactly 24 hours in a day. Most places have a 25 hour day once per year, and a 23 hour day once per year. ... @paulsm4 java.text.SimpleDateFormat ... More on stackoverflow.com
🌐 stackoverflow.com
java.sql.Date formatting - Stack Overflow
That shouldn't be the output of your code. java.util.Date.toString() formats the date in a different way. ... You already have a Date which can be formatted using SimpleDateFormat, you build your SQL date out of it; by curiosity, why do you want your SQL date formatted too? More on stackoverflow.com
🌐 stackoverflow.com
July 20, 2016
How do I parse a String into java.sql.Date format?

Can't your SQL server accept strings for dates? The ones I've used can, so I just do something like:

String sqlDate = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("dd-MM-yyyy").parse(startDate));

... and pass sqlDate to the parametrized query. Like konrad mentioned, lowercase 'mm' is for minutes, and uppercase 'MM' is for month, so I think that's where your problem was.

More on reddit.com
🌐 r/java
5
1
April 1, 2012
🌐
Coderanch
coderanch.com › t › 385771 › java › java-sql-Date-dd-mm
java.sql.Date to 'dd-mm-yyyy' format (Java in General forum at Coderanch)
Actually if you want something that's formatted as dd-mmm-yyyy it would have to be a String. A Date object doesn't have any format, it's just a date. Anyway to produce that String you should create a SimpleDateFormat object with the appropriate parameters, then call its format(Date) method ...
🌐
Oracle
docs.oracle.com › cd › E13222_01 › wls › docs45 › classdocs › java.sql.Date.html
Class java.sql.Date
This class is a thin wrapper around java.util.Date that allows JDBC to identify this as a SQL DATE value. It adds formatting and parsing operations to support the JDBC escape syntax for date values.
Find elsewhere
🌐
Dariawan
dariawan.com › tutorials › java › java-sql-date-examples
java.sql.Date Examples | Dariawan
July 24, 2019 - Here some methods available for java.sql.Date: void setTime​(long date): Sets an existing Date object using the given milliseconds time value. LocalDate toLocalDate(): Creates a LocalDate instance using the year, month and day from this Date object. This method available for Java 8 and above. String toString(): Formats a date in the date escape format yyyy-mm-dd.
🌐
Baeldung
baeldung.com › home › java › java dates › convert java.util.date to java.sql.date
Convert java.util.Date to java.sql.Date | Baeldung
January 13, 2024 - SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); isoFormat.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); java.util.Date date = isoFormat.parse("2010-05-23T22:01:02"); TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); java.sql.Date sqlDate = new java.sql.Date(date.getTime()); System.out.println(sqlDate); // This will print 2010-05-23 TimeZone.setDefault(TimeZone.getTimeZone("Rome")); sqlDate = new java.sql.Date(date.getTime()); System.out.println(sqlDate); // This will print 2010-05-24 · For this reason, we might want to consider one of the conversion alternatives that we’ll examine in the next subsections. The first alternative to consider is to use the java.sql.Timestamp class instead of java.sql.Date.
🌐
Oracle
docs.oracle.com › en › java › javase › 25 › docs › api › › java.sql › java › sql › Date.html
Date (Java SE 25 & JDK 25)
January 20, 2026 - If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT. ... date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT. ... Converts a string in JDBC date escape format to a Date value.
🌐
Reddit
reddit.com › r/java › how do i parse a string into java.sql.date format?
r/java on Reddit: How do I parse a String into java.sql.Date format?
April 1, 2012 -

Alright, so I've got a file that I am reading and importing dates into a database using SQL. In order to do this, I need to parse the date from the file into a java.sql.Date. Here is an example date.

01-16-2014

And I need it in a format like

2014-01-16

I tried this.

String startDate="01-06-2014";
SimpleDateFormat sdf1 = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date date = sdf1.parse(startDate);
java.sql.Date sqlStartDate = new java.sql.Date(date.getTime());

But I got an error saying that I couldn't parse a java.util.Date to a java.sql.Date through a method invocation. Is there an easy way to do this?

Thanks in advance for your help!

🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › sql › Date.html
Date (Java Platform SE 7 )
If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT. ... date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT. ... Converts a string in JDBC date escape format to a Date value.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › sql › Date.html
Date (Java Platform SE 8 )
3 days ago - If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT. ... date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT. ... Converts a string in JDBC date escape format to a Date value.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.sql › java › sql › Date.html
Date (Java SE 21 & JDK 21)
January 20, 2026 - If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT. ... date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT. ... Converts a string in JDBC date escape format to a Date value.
🌐
Experts Exchange
experts-exchange.com › questions › 23457892 › How-can-I-format-java-sql-Date.html
Solved: How can I format java.sql.Date ? | Experts Exchange
June 4, 2008 - A date in a database is a number (or certainly should be) - it has no format. You mean you want to format it when you print it? ... java.sql.Date d = new java.sql.Date(System.currentTimeMillis()); String date = String.format("%tm/%<td/%<tY\n", ...
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... Java does not have a built-in Date class, but we can import the java.time package to work with the date and time API.
🌐
Baeldung
baeldung.com › home › java › java dates › java.util.date vs java.sql.date
java.util.Date vs java.sql.Date | Baeldung
January 8, 2024 - Its main purpose is to represent SQL DATE, which keeps years, months and days. No time data is kept. In fact, the date is stored as milliseconds since the 1st of January 1970 00:00:00 GMT and the time part is normalized, i.e. set to zero. Basically, it’s a wrapper around java.util.Date that handles SQL specific requirements.
🌐
Coderanch
coderanch.com › t › 521898 › java › Convert-Java-sql-Date-String
Convert Java.sql.Date to String or Java.util.Date (Beginning Java forum at Coderanch)
December 29, 2010 - A java.sql.Date is already a java.util.Date, because class java.sql.Date is a subclass of java.util.Date. Date objects do not have formats by themselves. To display a date in a specific format, you format it with a DateFormat object.