显示两个日期之间的记录

时间:2014-04-16 08:39:42

标签: jsp date odbc

我使用msaccess和jsp。我想显示当前值为sysdate或大于2周sysdate的所有记录。对于试验我将todate与sysdate进行比较。但它显示了NUll pinter Exception。

      <%@page contentType="text/html" pageEncoding="UTF-8"%>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
      <%@ page import="java.sql.*"%>
      <%@ page import="java.util.Calendar"%>
       <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>JSP Page</title>
</head>
<body>


<%

         java.text.DateFormat df = new java.text.SimpleDateFormat("dd/MM/yy");
      java.util.Date currentDate =new java.util.Date();
         java.sql.Date sqlDate = new java.sql.Date(currentDate.getTime());
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       String sSql ="SELECT ADDRESS,FinancialYear,Todate from backup where Todate=?";
      String sDBQ = "C://Users/vishnu priya/Documents/amc.mdb";
     String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + sDBQ                  + ";DriverID=22;READONLY=true";
      Connection cn = null;
     Statement st = null;
    ResultSet rs = null;
   PreparedStatement pre=null;
       try {
             cn = DriverManager.getConnection( database ,"","");
                pre = cn.prepareStatement(sSql);
          pre.setDate(1,sqlDate);
           %>
       <table border='2' vspace='80'>
        <%
         out.println("<thead>");
          out.println("<tr>");
         out.println("<th>Customer Name</th>");
         out.println("<th>Financial Year</th>");
          out.println("<th>To Date</th>");
         out.println("</tr>");
        out.println(" </thead>");
        String add="";
        String fin="";
       String to="";
         while(rs.next())
             {
          add=rs.getString(1);
        fin=rs.getString(2);
        to=rs.getString(3);

         %>
          <tr>


        <td><%=add%></td>
         <td><%=fin%></td>
       <td><%=to%></td>
         <%
    }
     cn.close();

      }
   catch(Exception e)
     {
     out.println(e);
 e.printStackTrace();
       }
     %>
     </body>
     </html>

0 个答案:

没有答案