Oracle Database Memory During Time, Division, Seconds

xiaoxiao2021-03-06  36

Storage and read (read, minute, second) in the Oracle database

The format in the general database is a Date type, and the time we get from the page is often a String type, which requires the type of conversion. Generally we convert it by calling the Java.Text.SIMPLEDATEFORMAT JAVA class. There are two methods we often use in this Java class, one is format (converts data in time format to string type), and the other is PARSE (convert the String type to a Date type). We can generally encapsulate Parse into their own way, examples: / ** * Method description: The string in the page is translated into a date type * * Input parameters: Date data indicated by string forms from the page * Output parameters : Date of conversion * /

Public class timeexh {public static datetrage; {date date = null; // is 2005-1-13 SimpleDateFormat SDF = New SimpleDateFormat ("YYYY-MM-DD"); "YYYY-MM-DD"); // Establish a certain format SimpleDateFormat if (strdateFromPage == null) {Return New Date ();} if (strdateFromPage.Length ()> 10) {SDF = New SimpleDateFormat ("YYYY-MM-DD HH: mm: ss "); // This time is 2005-1-13 20:00:12} try {date = SDF.PARSE (STRDATEFROMPAGE);} catch (exception ex) {ex.printstacktrace ();} returnate;} }

The way to_date is provided in the Oracle database to convert the String type time. In the Oracle database, the time cannot be passed directly into the VO to the database, so that the time in the database is Green's time, which does not conform to the Chinese time habits. Therefore, there are two different processing methods here.

The first type: The type of storage time in Vo is a String type. I am here to write a simple VO as: public class datevo {........ / / omitted the defined section Public void setStart_date (string start_date) {start_date = start_date}

Public string getStart_date () {return this.start_date;} / ** * Judgment Start_date is empty * / public boolean ISEMPTYSTART_DATE () {if (this.start_date == Null || this.start_date.equals (")) { Return true;}}}} // a. The transfer parameters are Date type // Get the current time, pass the value to VO: SimpleDateFormat SDF = New SimpleDateFormat ("YYYY-MM-DD HH: mm : SS "); // convert the current time to YYYY-MM-DD HH: mm: SS format string nowDate = sdf.format (new date ()); // put this String value into the setDate () Method. Vo.Setdate (nowDate); / / Get the time value from VO when the SQL statement is organized. The front portion of the SQL statement is omitted, mainly the processing of the time of the rear portion. SBSQL.Append (INSERT INTO NEWS (START_DATE, ....) Value (); if (! Vo.isemptyStart_date ()) {sbsql.append (""); sbsql.append ("to_date ('"); //// To_date is a function of the conversion time in the Oracle database, the processing object is string sbsql.append (vol.getStart_date ()); sbsql.append ("',' YYYY-MM-DD HH24: MI: SS ')"); /////// Note this line of code, the format is correct, otherwise it will not get, minute, second} else {sbsql.append ("null");} SBSQL.Append ("....)");

// b. The transfer parameters are String type (from page acquisition) IF (Request.GetParameter ("start_date")! = Null &&! Request.getParameter ("start_date"). Equals (")) {// The string value is put into the setDate () method in Vo. Vo.Setdate;} After processing the same thing ........

The second type: The type of storage time in Vo is a DATE type. Public class datevo {........ / 省 省 定 部分 Public void setstart_date (date start_date) {start_date = start_date}

Public Date getStart_date () {return this.start_date;} / ** * Judgment Start_date is empty * / public boolean == Null || this.start_date.equals (")) { Return true;}}}} // a. The transfer parameters are Date type // Get the current time, pass the value to VO: SimpleDateFormat SDF = New SimpleDateFormat ("YYYY-MM-DD HH: mm : SS "); string nowdate = SDF.Format (new date ()); // converts the current time to YYYY-MM-DD HH: mm: SS format put this string value into the setDate () method in VO . Vo.Setdate (timeexh.transtodate (nowDate)); // Get the time value from VO when the SQL statement is organized. The front portion of the SQL statement is omitted, mainly the processing of the time of the rear portion. SBSQL.Append ("INSERT INTO NEWS (START_DATE, ....) Value ("); if (! ") {sbsql.append (" "); sbsql.append (" to_date ('"); SBSQL.Append (sdf.format (vol.getStart_date ())))); sbsql.append ("'YYYY-MM-DD HH24: MI: SS')");} else {sbsql.append ("null") }

SBSQL.Append ("....)"); // b. The transfer parameters are string type if (Request.GetParameter ("start_date")! = null &&! Request.getParameter ("start_date"). Equals (" ")) {// put this string value into the setDate () method in VO. Vo.Setdate (TimeExh.TranStodate (Request.getParameter)));} // After processing the same .........

转载请注明原文地址:https://www.9cbs.com/read-65042.html

New Post(0)