Servlet connection database and date format conversion

Source: Internet
Author: User
Tags openid

Package Oraclefactory;import Java.io.ioexception;import java.io.printwriter;import java.sql.connection;import Java.sql.drivermanager;import Java.sql.resultset;import Java.sql.sqlexception;import Java.sql.Statement;import Java.text.simpledateformat;import Java.util.calendar;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.HttpServletResponse; Public classTESTWX extends httpservlet{PrivateString URL; PrivateString User; PrivateString password; PrivateString Driverclass;  Public voidinit () throws Servletexception {Driverclass="Oracle.jdbc.driver.OracleDriver"; Try{class.forname (driverclass); } Catch(ClassNotFoundException E1) {//TODO auto-generated Catch blockE1.printstacktrace (); } URL="Jdbc:oracle:thin: @IP: 1521:sas"; User="XXX"; Password="XXX"; }         Public voiddoget (HttpServletRequest req,httpservletresponse resp) throws ioexception,servletexception{Conne Ction Conn=NULL; Statement stmt=NULL; ResultSet RS=NULL; Req.setcharacterencoding ("gb2312"); Resp.setcontenttype ("text/html;charset=gb2312"); PrintWriter out=Resp.getwriter (); Calendar Calendar=calendar.getinstance (); SimpleDateFormat SD1=NewSimpleDateFormat ("YYYY-MM-DD 00:00:00"); SimpleDateFormat SD2=NewSimpleDateFormat ("YYYY-MM-DD 23:59:59"); String Today=Sd2.format (Calendar.gettime ()); Calendar.add (Calendar.date,-7); String Lastmon=Sd1.format (Calendar.gettime ()); System. out. println (Lastmon); System. out. println (today); Try{conn=drivermanager.getconnection (URL, user, password); stmt=conn.createstatement (); String SQL="SELECT * from Wx_run_user a,wx_run_user_state b where a.openid=b.wx_user_id and a.sex=2 and a.last_mod_time between 
    "+"to_date ('"+lastmon+"' , ' yyyy-mm-dd HH24:Mi:ss ') and To_date ('"+today+"' , ' yyyy-mm-dd HH24:Mi:ss ')"; System. out. println (SQL); RS=stmt.executequery (SQL);  out. println ("");  out. println ("<table border=1 align=center><caption> interface Information </caption>");  out. println ("<tr><th>openid</th><th> nickname </th><th> Avatar Address </th><th> binding mode </th ><th> binding number </th><th> creation time </th><th> Last modified time </th><th> account status </th>< /tr>");  while(Rs.next ()) { out. println ("<tr>");  out. println ("<td>"+rs.getstring ("OpenID")+"</td>");  out. println ("<td>"+rs.getstring ("Nickname")+"</td>");  out. println ("<td>"+rs.getstring ("Headimgurl")+"\ "Width=300/></td>"); String Bind_type=rs.getstring ("Bind_type"); intby =integer.valueof (Bind_type). Intvalue (); Switch(by) { Case 0: Bind_type="Phone number";  Break;  Case 1: Bind_type="fixed";  Break; default: Bind_type="Broadband Account";  Break; }                 out. println ("<td>"+bind_type+"</td>");  out. println ("<td>"+rs.getstring ("NBR")+"</td>");  out. println ("<td>"+rs.getstring ("Create_time")+"</td>");  out. println ("<td>"+rs.getstring ("Last_mod_time")+"</td>"); String Acc_status= Rs.getstring ("Acc_status"); intStatus =integer.valueof (acc_status). Intvalue (); Switch(status) { Case 0: Bind_type="Cancel your attention";  Break;  Case 2: Bind_type="attention and binding";  Break; default: Bind_type="Focus on Unbound";  Break; }                 out. println ("<td>"+bind_type+"</td>");  out. println ("</tr>"); }             out. println ("</tr></table></body>");  out. println ("Success");  out. Close ();            Stmt.close ();                    Conn.close (); } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }                    }}

Servlet connection database and date format conversion

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.