开发者

how to get the timestamp taken to insert the data into a table

开发者 https://www.devze.com 2023-03-25 09:38 出处:网络
I amstoringimages 开发者_如何学Pythonin a tablei would like to get the time stamp taken toinsert the image into the table are their anyinboundsql syntax for getting thetimestamp of inserted data ? or

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消