This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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!
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
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.
================= 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?
Joined: Aug 15, 2004
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.