Java createsqlquery (). List () returns the date format without a time and seconds resolution (GOTO) a solution for a Java project that uses the date type not to display the seconds and minutes 2010-04-21 21:35:00| Classification: Java Technology | font size subscription yesterday, Antioch (Network Space-time) in the development of Web projects, found to extract some of the date types of Oracle field, found that the proposed date value, only "Month Day", no "time and minute" display, the actual business, It is required that the date requested on the page be "month and day is seconds". Here, I am using Session.createsqlquery (SQL). List () to return the value of the value type is List (object[]). Although, I was using SSH, because here SQL corresponds to a business situation involving complex multi-table queries, If you use hibernate for mapping, the difficulty is very large, and the coding will be very difficult. So here we have to use the original SQL or standard SQL to return the value. specific detailed questions are as follows in SSH for the following statement session.createsqlquery (SQL). list (); query, return a list<object[]> In the list loop, I find that when the value of the date type is displayed, only "Month Day" is displayed, and no "hours seconds" for (object[] obj:session.createSQLQuery (SQL) is displayed. List ()) { ... SYSTEM.OUT.PRINTLN ("Receipt date is" + (date) obj[5]); //only displays the month and day, does not show "time and minute" such as 2010-03-01 // The value of the corresponding field in the Oracle data table is actually 03-01-2010 16:31:14 ...} toss after a half-day, after netizens remind, and my patient test, finally found the solution method one will oracel the database corresponding table in the "receipt of the Time field" Receive_sheet_time, Change from the original date type to timestamp then, in a Java program, the return value of (Java.util.timestamp) obj[5] will show "month and minute seconds". such as 2010-03-01 14:39:17 Method Two oracleoracel the field in the "Receipt time" receive_sheet_time in the corresponding table of the database, the field continues to hold the date type in the SQL statement above, returning the "field of the receipt date" Receive_ Sheet_time, becomes to_char (Loading.receive_sheet_time, ' Yyyy-mm-dd hh24:mi:ss ') as Receive_sheet_time returns a value as a string type, Then, in a Java program, the return value, by (String) obj[5], will show "month and minute". such as 2010-03-01 14:39:17 attached: As for the date and the timestamp type of difference, I will not say, friends can go online a search to know Original Sqlselect load_point, dispatch_no, schedule_no, truck_no, trans_date, trans_company_name, departure_time, trans_company_code, receive_sheet_time, dispatch_sheet_time, loading_time, sum (Expected_qty) as expected_qty, sum (Allocate_qty) as Allocate_qty, sum (Real_qty) as real_qty  From (SELECT odetail.load_point, dispatch.dispatch_no, odetail. schedule_no, dispatch.trans_company_code, & nbsp dispatch.truck_no, to_char ( Dispatch.trans_date, ' Yyyy-mm-dd ') as trans_date, dispatch.trans_ company_name, odetail.expected_qty, &NBS P odetail.allocate_qty, odetail.real_qty, loading.receive_sheet_time, &NBSP ; loading.dispatch_sheet_time, loading.loading_time, loading.departure_time from T_dispatch dispatch, t_order_detail &nbs P odetail, t_dispatch_detail tdetail, &NBSP ; t_dispatch_loading loading where Dispatch.dispatch_no = tdetail.dispatch_no and odetail.order_no = tdetail.order_no and odetail.order_line_no = tdetail.order_line_no and loading . Dispatch_no = dispatch.dispatch_no and loading.load_point = odetail.load_point& nbsp and dispatch.status <> 99 and NVL (Dispatch . b_cancel, 0) = 0) where 1 = 1 and to_char (departure_time, ' yyyy-mm-dd HH24:MI:SS ') >= ' 2010- 04-07 00:00:07 ' and to_char (departure_time, ' yyyy-mm-dd HH24:MI:SS ') <= ' 2010-04-07 23:59:07 ' group by load_point, dispatch_no, & nbsp schedule_no, truck_no, trans_date, trans_company_name, departure_time, tra ns_company_code, receive_sheet_time, dispatch_sheet_ time, Loading_time order by Dispatch_no, Schedule_no, load_point New SQL statement (the red part of the SQL statement below, which is the type of date I will return, the conversion to the To_char type returns: Use the method for a while, with the original SQL on the line) select load_point, dispatch_no, schedule_no, truck_no, trans_date, trans_company_name, departure_time, trans_company_code, receive_sheet_time, dispatch_sheet_time, loading_time, sum (Expected_qty) as expected_qty, sum ( Allocate_qty) as allocate_qty, sum (Real_qty) as real_qty from (SELECT odetail.load_point , dispatch.dispatch_no, &NB Sp odetail. schedule_no, dispatch.trans_company_code, & nbsp dispatch.truck_no, to_char ( Dispatch.trans_date, ' Yyyy-mm-dd ') as Trans_date, dispatch.trans_company_name, &NBS P odetail.expected_qty, odetail.allocate_qty, & nbsp odetail.real_qty, to_char (l Oading.receive_sheet_time, ' Yyyy-mm-dd hh24:mi:ss ') as receive_sheet_time, to_char (loading.dispatch_sheet_time, ' Yyyy-mm-dd hh24:mi:ss ') as dispatch_sheet_time, to_char (loading.loading_time, ' Yyyy-mm-dd hh24:mi:ss ') as loading_time, & nbsp to_char (loading.departure_time, ' Yyyy-mm-dd hh24:mi:ss ') as Departure_time from @DBUSer t_dispatch dispatch, &NBSP ; @DBUSer. T_ordEr_detail odetail, @DBUSer. T_dispatch_detail &NBSP;TD etail, @DBUSer. t_dispatch_loading loading &NBSP ; where dispatch.dispatch_no = tdetail.dispatch_no and odetail.order_no = tde tail.order_no and odetail.order_line_no = tdetail.order_line_no & nbsp and loading.dispatch_no = dispatch.dispatch_no and Loading.lo Ad_point = odetail.load_point and dispatch.status <> 99 and NVL (dispatch.b_cancel, 0) = 0) where 1 = 1 @var1 &NB Sp group by load_point, dispatch_no, &N Bsp Schedule_no,&nbSp truck_no, trans_date, Tran s_company_name, departure_time, trans_company_code,& nbsp receive_sheet_time, dispatch_sheet_time, &NBSP ; Loading_time order by Dispatch_no, Schedule_no, Load_point
Java createsqlquery (). List () returns the resolution of the date format without seconds and minutes (go)