ramoore
asked on
SQL INSERT system date into table
Hi,
I have created a table called "myTable" with a column called CURRENT_DATE and it's data type is "DATE". When I programatically update my table, I also want to place a timestamp or system date in the CURRENT_DATE field. A portion of what I am doing is shown below, but it is not working. I would think this would be easy, but... Can you help?
...
//System date is captured for placement in the CURRENT_DATE field in myTable
java.util.Date currentDate = new java.util.Date();
...
stmt.executeQuery("INSERT INTO myTable (NAME, CURRENT_DATE) VALUES (' " + userName + " ', ' " + currentDate + " ') ");
...
I have created a table called "myTable" with a column called CURRENT_DATE and it's data type is "DATE". When I programatically update my table, I also want to place a timestamp or system date in the CURRENT_DATE field. A portion of what I am doing is shown below, but it is not working. I would think this would be easy, but... Can you help?
...
//System date is captured for placement in the CURRENT_DATE field in myTable
java.util.Date currentDate = new java.util.Date();
...
stmt.executeQuery("INSERT INTO myTable (NAME, CURRENT_DATE) VALUES (' " + userName + " ', ' " + currentDate + " ') ");
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, and if the userName is the user that was logged into the database (not a shared database user, but unique and tied to the userName in your app, you could use:
stmt.executeQuery("INSERT INTO myTable (NAME, CURRENT_DATE) VALUES (user,sysdate) ");
user is another special column that is the currently logged in user in the database. the user that was used in the connect statement.
stmt.executeQuery("INSERT INTO myTable (NAME, CURRENT_DATE) VALUES (user,sysdate) ");
user is another special column that is the currently logged in user in the database. the user that was used in the connect statement.
ASKER
Thanks everyone for the quick response! sysdate worked great.
Does Oracle have its own Current Date Generator? Could you do: VALUES (' " + userName + " ', CURDATE())"
Joe P