I am storing images 开发者_如何学Pythonin a table i would like to get the time stamp taken to insert the image into the table are their any inbound sql syntax for getting the timestamp of inserted data ? or any java syntax for getting the timestamp of inserted data from the database kindly help out
CURRENT_TIMESTAMP
is a function that is available in most database servers. So a sql like this should work.
INSERT INTO <some_table> (<timestamp_column_name> VALUES (CURRENT_TIMESTAMP)
If you want to do it in java then you can do the following:-
java.util.Date currentTime = new java.util.Date();
System.out.println(new java.sql.Timestamp(currentTime.getTime())); //gets you the current sql timestamp
It is going to vary by database. This is going to work in both least Oracle and mysql:
insert into PRODUCE (color, weight, added_at) values ('red', '8 ounces', sysdate());
If you are using MySql, you can also add DEFAULT CURRENT TIMESTAMP to your column definition:
create table PRODUCE (
color varchar(20),
weight varchar(20),
added_at TIMESTAMP DEFAULT CURRENT TIMESTAMP
);
insert into PRODUCE (color, weight) values ('red', '8 ounces');
In Oracle, a separate trigger would need to be created to achieve the default value.
精彩评论