This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes sql.date trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sql.date trouble" Watch "sql.date trouble" New topic
Author

sql.date trouble

k mull
Greenhorn

Joined: Dec 15, 2004
Posts: 5
Hi,

I have a table in my database where one of the entries is a 'Date' in the format 'DD-MMM-YY'. I need to create the date myself and enter it into this table but I dont know how to get it in the correct DD-MMM-YY format.

I can create a new Date() using but i can't get it in the format I need.
Also when I pass this new date into the database it returns an error because it is not of type java.sql.date so it doesn't work that way!

Any help would be much appreciated!
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
TryThis puts the wrapper on the date object that should allow JDBC to identify this as an SQL DATE value.

Also, this is probably more appropriate in another forum.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Anandh Ramesh
Ranch Hand

Joined: Dec 15, 2004
Posts: 61
you can try using this method.

Calendar cal = new GregorianCalendar();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);

you can do the necessary modification and insert it, in whichever format, using any separator desired.

this is a bit roundabout, but it works.

-Anandh


cheers,<br />Anandh
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
format doesn't matter while putting into DB. Database could have someother format of its own. so do the same what Paul's said. and format the date while getting it from DB. you can do that by using java.text.SimpleDateFormat class.

and let me say. it is really simple as name describe. what you need to do is just look the docs once.

cheers.
[ December 18, 2004: Message edited by: Adeel Ansari ]
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
=================
java.sql.date myDate = new java.sql.date(new java.util.date().getTime());

==============================

Replace date by Date if cut/pasting the above code

What is the syntax if I want to have the date in dd/mm/yyyy format to be inserted in the table column of a database?

Rgds,

Seetesh
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874

ormat doesn't matter while putting into DB. Database could have someother format of its own. so do the same what Paul's said. and format the date while getting it from DB. you can do that by using java.text.SimpleDateFormat class.


as said earlier.
cheers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sql.date trouble
 
Similar Threads
Converting string to specific date format
BigDecimal to Date Conversion
Date Format Problem
updating date field
Formatting Date Object