JSP uses the database connection pool method to obtain the database timestamp context.xml configuration, the JSP page formats the time into its own need format

Source: Internet
Author: User

<?XML version= "1.0" encoding= "UTF-8"?> <!--database Connection pool configuration file - <Context>    <Resourcename= "Jdbc/connectionpool"Auth= "Application"type= "Javax.sql.DataSource"username= "root"Password= "root"Driverclassname= "Com.mysql.jdbc.Driver"URL= "jdbc:mysql://localhost:3306/pwapplication?relaxautocommit=true&amp;zerodatetimebehavior= Converttonull "maxactive= "8"Maxidle= "4"        /> </Context>

Then add code to the JSP page and get the time to format the time as you want.

<%@ page language= "Java"Import= "java.util.*" pageencoding= "UTF-8"%><%@ pageImport= "java.sql.*"%><%@ pageImport= "javax.naming.*"%><%@ pageImport= "Javax.sql.datasource,java.text.format,java.text.dateformat"%><%@ pageImport= "Java.text.SimpleDateFormat"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >Context Initctx=NewInitialContext (); Context CTX= (Context) initctx.lookup ("Java:comp/env")); //Get Connection Pool objectDataSource ds = (DataSource) ctx.lookup ("Jdbc/connectionpool"); //Create a connectionConnection conn =ds.getconnection (); System.out.println ("Conn=" +conn); Statement stmt=conn.createstatement (); String MySQL= "SELECT * FROM NOTIFICATION_TB"; ResultSet myrs=stmt.executequery (MySQL);//Execute Query%> <body>notification message list:<% while(Myrs.next ()) {%> <%String notiid=myrs.getstring ("Notiid"); String Notitheme=myrs.getstring ("Notitheme"); String noticontent=myrs.getstring ("Noticontent"); String notifier=myrs.getstring ("Notifier"); Timestamp Notitime=myrs.gettimestamp ("Notitime"); //set the time formatSimpleDateFormat SPF =NewSimpleDateFormat ("yyyy mm month dd Day hh mm min ss sec"); //format TimeString fmttime=Spf.format (notitime); %> <%System.out.println (Notitheme);                System.out.println (noticontent);                System.out.println (Notitime);              System.out.println (Fmttime); %> <dt>>><a href= "notidetail?notiid=<%=notiid%>" ><%=notitheme%></a&                        gt;</dt> <dd> <div align= "right" > Publisher: <%= notifier%> </div> </dd> <%        }     %> </body>

JSP uses the database connection pool method to obtain the database timestamp context.xml configuration, the JSP page formats the time into its own need format

Related Article

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.