java.sql.SQLException:[Microsoft] [ODBC Microsoft Access驱动程序]查询表达式中日期中的语法错误

时间:2015-05-26 10:21:38

标签: jsp ms-access jdbc

有人可以帮我解决错误吗?我在String ex:"01-JAN-2015"

中将日期setString作为参数传递时出错
  

javax.servlet.ServletException:java.sql.SQLException:   [Microsoft] [ODBC Microsoft Access驱动程序]日期中的语法错误   在#Pa_RaM000#和#Pa_RaM001#'之间查询表达式'(Event_Dairy)。

    String url="jdbc:odbc:kaso";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
    Connection conn=DriverManager.getConnection(url);       
    PreparedStatement ppdsmt=conn.prepareStatement("select * from Event_Dairy where(Event_Dairy) between #?# and #?#");
    ppdsmt.setString(1,sdate); 
    ppdsmt.setString(2,edate); 
    ResultSet rs=ppdsmt.executeQuery();
    if(!rs.next())
    {
        out.println("NO RECORDS FOUND");
    }
    else
    {%>
        <table border="2">           
         <tr>
             <td>Event Date</td>
             <td>Subject</td>
             <td>Subject Heading</td>
        </tr>
        <%
        do
        {
            eventDate=rs.getString("Event_Dairy");  
            System.out.println("Event Date"+eventDate);
            Subject=rs.getString("Subject");
            Subject_Heading=rs.getString("Subject_Heading"); 
         %>
          <tr>
                <td><%=eventDate%></td>
                <td><%=Subject%></td>
                <td><%=Subject_Heading%></td>
          </tr>
        <%
        }while(rs.next());
    }

1 个答案:

答案 0 :(得分:1)

使用java.sql.Date(或java.sql.Timestamp)代替String。见Using setDate in PreparedStatement

查询中的#占位符周围没有?个字符。