The string date is converted to the Oracle. jbo. domain. Date and Oracle. jbo. domain. timestamp types.

Source: Internet
Author: User

Description:
In the normal development process, we will find that there are many types of dates, including Java. lang. date, Java. SQL. date, Oracle. jbo. domain. date, And the timestamp oracle. jbo. domain. timestamp and so on. Conversion between these types is also common. The description date string is converted to the Oracle. jbo. domain. Date and Oracle. jbo. domain. timestamp types.

Requirements:
Find the employment date (hire_date) in the Employees table of the Xe database before a certain time (defined by yourself), and the job ID (job_id) only belongs to ('ad _ pres ', 'Ad _ vp', 'it _ prog') three types of employees.

Implementation:

It is very easy to simply use SQL statements to query, for example.

Select * from employees <br/> where job_id in ('ad _ pres', 'ad _ vp', 'it _ prog ') <br/> and hire_date <= to_date ('2017/1', 'yyyy/DD/mm ')

To better address the problem, we use the subquery method to query qualified employees.

1. Create an employee Seo and employeesvo Based on the table employees. Create a subquery in employeesvo to query qualified employees. First, create a binding variable on vo.

2. Then create a subquery employeesvc in Vo, and bind the hiredate attribute to the binding variable bvhiredate created above.

3. Create the jspx page and searchemployees. jspx. The layout is roughly as follows:

4. Generate the corresponding backingbean and searchemployees class, bind the search action to the searchaction method, and process the query logic. First, bind the inputdate component on the interface to backingbean, retrieve the value entered on the interface in the background, and then convert the obtained string date to Oracle. jbo. domain. date or Oracle. jbo. domain. timestamp type.

First, write it in the searchemployees class of backingbean.

Public class searchemployees extends custommanagerbean {<br/> private richinputdate inputdate; <br/> Public searchemployees () {<br/>}< br/> Public void setinputdate (richinputdate inputdate) {<br/> This. inputdate = inputdate; <br/>}< br/> Public richinputdate getinputdate () {<br/> return inputdate; <br/>}</P> <p> Public String searchaction () {<br/> string indate = This. getinputdate (). getvalue (). tostring (); <br/> system. out. println (indate); <br/> dateformat formatter; <br/> JAVA. util. date = NULL; <br/> timestamp time = NULL; </P> <p> try {<br/> formatter = new simpledateformat ("yyyy-mm-dd hh: MM "); <br/> date = formatter. parse (indate); <br/> time = new timestamp (date. gettime (); <br/> system. out. println (time); </P> <p >}catch (parseexception e) {<br/> E. printstacktrace (); <br/>}</P> <p> operationbinding binding = This. findoperation ("Search"); <br/> binding. getparamsmap (). put ("time", time); <br/> binding.exe cute (); <br/> return NULL; <br/>}< br/>

Implement the search method in the implementation class of AM

Public void search (timestamp time) {<br/> employeesvoimpl Vo = (employeesvoimpl) This. getemployeesvo1 (); <br/> vo. setbvhiredate (time); <br/> viewcriteria Vc = Vo. getviewcriteria ("employeesvc"); <br/> vo. applyviewcriteria (VC); <br/> vo.exe cutequery (); <br/>}

5. Running result

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.