简体   繁体   中英

Getting Time as 00:00:00.0

below is my stored procedure

create procedure sp_process_job(@request_id varchar(25), @host varchar(20),
     created_on varchar(25)
) 
as
begin

    set dateformat mdy
    SELECT CAST(@created_on as datetime)
    insert into t_job_details(request_id ,host, created_on) 
    values(@request_id,@host,@created_on)

end

When I cast date using SELECT CAST(@created_on as datetime)

I get output as 2012-06-22 00:00:00.0 Time is 00:00:00.0

I want it as 12:45:06.0 . Why I get 0 in all places?

Edit: Calling the above procedure from java code

Date date = new Date();
Date insert_date = new java.sql.Date(date.getTime());
String insertquery = "{ call sp_process_job (?,?,?) }";

cs = con.prepareCall(insertquery.toString());
            cs.setString(1, id);
            cs.setString(2, host);
            cs.setDate(3, (java.sql.Date) insert_date);
cs.execute();

            con.commit();

I guess you should use java.sql.Timestamp in the Java code instead of java.sql.date which saves only date not time. And also cs.setTimestamp

    java.sql.Timestamp insert_date = new java.sql.Timestamp(date.getTime());
    ....
    cs.setTimestamp(3, insert_date);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM