Hi to all,
I have a PostgreSql database table which contains field of type date .I want to insert the date in the format of “dd-MMM-YYYY”. I am using the preparedStatement to insert the date field as well as other fields to the table.Please help me.
Regards,
Hyson
-
Inserting java.sql.Date type variable to database (4 messages)
- Posted by: Hyson Mathew
- Posted on: November 27 2005 23:56 EST
Threaded Messages (4)
- Inserting java.sql.Date type variable to database by umar ali on November 28 2005 12:08 EST
- Problem whileInserting java.sql.Date type variable to database by Hyson Mathew on November 29 2005 06:16 EST
-
Problem whileInserting java.sql.Date type variable to database by umar ali on December 01 2005 01:19 EST
- thanks by Hyson Mathew on December 02 2005 01:41 EST
-
Problem whileInserting java.sql.Date type variable to database by umar ali on December 01 2005 01:19 EST
- Problem whileInserting java.sql.Date type variable to database by Hyson Mathew on November 29 2005 06:16 EST
-
Inserting java.sql.Date type variable to database[ Go to top ]
- Posted by: umar ali
- Posted on: November 28 2005 12:08 EST
- in response to Hyson Mathew
you can insert the date as
pstmt.setDate(new java.util.Date(person.getBirthDate().getTime()));
where, person is a reference to a class Person.
The date will be inserted in yyyy-mm-dd format.
you can use the sql date formatting options for outputting it the way u like -
Problem whileInserting java.sql.Date type variable to database[ Go to top ]
- Posted by: Hyson Mathew
- Posted on: November 29 2005 06:16 EST
- in response to umar ali
Thanks umar ali for your reply and help. I have tried that way but there is no date formating functions are avail for the class java.sql.Date which are compactable with the pst.setDate() method (where pst is the reference to the type java.sql.PreparedStatement).The pstmt.setDate(1,date) method only accept java.sql.Date type arguments.So I didn’t got the expected result -
Problem whileInserting java.sql.Date type variable to database[ Go to top ]
- Posted by: umar ali
- Posted on: December 01 2005 13:19 EST
- in response to Hyson Mathew
The date formatting functions are not in java.sql. package but your database vendors provide the formatting functions for outputting the date. For ex.
SELECT BIRTHDATE(TO_DATE("DD-MM-YYYY")) FROM USER;
Check ur database vendor manual for details -
thanks[ Go to top ]
- Posted by: Hyson Mathew
- Posted on: December 02 2005 01:41 EST
- in response to umar ali
thanks for your reply .I will try