OSCache缓存技术(8)【JSP页面从数据库取得数据缓存列子】

index.jsp

<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="GB2312" isELIgnored="false"%>
<%@ taglib prefix="cache" uri="oscache" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>

<%
    Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf-8";
        String user = "root";
        String pwd = "root";
        
        List<String> lists =new ArrayList<String>();
        try
     {
      String sql = "select * from kindergarden_user";
      Class.forName(driver);
      con = DriverManager.getConnection(url,user,pwd);
      stmt = con.createStatement();
      rs = stmt.executeQuery(sql);
      while(rs.next())
      {
       String name = rs.getString("Name");
       lists.add(name);
      }
      
      
     }
     catch(Exception e3)
     {
      e3.printStackTrace();
     }
        finally
        {
         try
         {
         
         }
         catch(Exception ee)
         {
          try {
      rs.close();
      stmt.close();
      con.close();
     } catch (Exception exx) {
      exx.printStackTrace();
     }
         }
        }      
 
           

 %>
  <%=new java.util.Date()%>
  <br/>
 <%
  for(int i=0;i<lists.size();i++)
  {
   out.println((String)lists.get(i));
  }
  %>
  <br/>
 <cache:cache time="30">
 缓存中的List:
 <%
  for(int i=0;i<lists.size();i++)
  {
   out.println((String)lists.get(i));
  }
  %>
 </cache:cache>
</body>
</html>

 

你可能感兴趣的:(java,sql,mysql,jsp,cache)