Reputation: 56
I want to insert the current date to my oracle database Bills. I am getting the date from system using
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
is that possible to directly insert it into the database without converting to the default format (dd-month-yyyy
) of DATE data type in Oracle?
Upvotes: 2
Views: 40814
Reputation: 6137
Just in case you need CURRENT date, use:
INSERT INTO YOUR_TABLE (YOUR_DATE_COLUMN, COLUMN_2, COLUMN_3)
VALUES (SYSDATE, 1234, 567);
Upvotes: 13
Reputation: 20069
You did not give any context on what interface you are using to communicate with the DB. Assuming plain JDBC, let the driver handle the problem, use a statement object and set the parameter(s) properly:
Connection connection = ...
PreparedStatement statement = connection.prepareStatement("INSERT INTO <TableNameHere> VALUES (?)");
statement.setObject(1, new java.sql.Date());
statement.executeUpdate();
(Error handling and fluff ommited) The JDBC driver will deal with the details on how to format the date as the database wants it. Don't even worry about it.
Upvotes: 5
Reputation: 1735
1) It is not mandatory to use the default dd/MM/yyyy format in while initializing SimpleDateFormatter. You have a list of options which can match to your requirement. SimpleDateFormat
Upvotes: 0