In the Oracle Database, the time format in the general database in the general database in the Oracle database is a Date type, and the time taken from the page is often a String type, this 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 datetrodate {date date = null; // is YYYY-MM-DD 2005-1-13 SimpleDateFormat SDF = New SimpleDateFormat ("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: s "); // This time is 2005-1-13 20:00:12} try {date = sdf.parse (strdateFromPage);} catch (exception ex) {EX.PrintStackTrace );} Return Date;}} 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: public class datevo {........ 省 省 省 定 定 部分 部分 部分 (STRING START_DATE) {start_date = start_date} public string getStart_date () {Return THIS .Start_date;} / ** * Judging whether start_date is empty * / public boolean ISemptyStart_date () {if (this.start_date == null || this.start_date.equals (")) {return true;} else {Return False ;}}} // 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"); // Current time is converted to YYYY-MM-DD HH: mm: SS format string nodate = sdf.format (new date ()); // put this string value into the setDate () method in VO. 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 be reached, minute, second} else {sbsql.append ("null");} SBSQL.Append ("...)"); // b. The parameter is a string type (from page acquisition) if (Request.GetParameter)! = Null&&! Request.getParameter ("start_date"). Equals (")) {// put this string value into VO In the setDate () method. Vo.Setdate;} Back processing is the same ...
Public class datevo {........ / 省 省 省 部分 部分;;;;;;;;;; () Whether it is empty * / public boolean ISemptyStart_date () {if (this.start_date == null || this.start_date.equals (")) {return true;}}} // a. The parameter is DATE type // Gets the current time, and passes the value to VO: SimpleDateFormat SDF = New SimpleDateFormat ("YYYY-MM-DD HH: MM: SS"); string nowDate = SDF.FORMAT (new date ()); // convert the current time to YYYY-MM-DD HH: MM: SS format A setDate () method in Vo in the SS format. 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. (")) {/ {/ In the setDate () method in VO, put this string value. Vo.SetDate (Request.GetParameter ("start_date")));} // After processing the same ......... Author Blog:
http://blog.9cbs.net/homecat/