0
我有下面的jsp。java.sql.SQLException:[Microsoft] [ODBC Excel驅動程序]條件表達式中的數據類型不匹配
<%--
Document : See_Free_Editors
Created on : Aug 16, 2013, 7:22:30 PM
Author : u0138039
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
$(".datepicker").datepicker();
});
xmlHttp = new XMLHttpRequest();
function getUsers()
{
xmlHttp.onreadystatechange=
function()
{
if(xmlHttp.readyState===4 && xmlHttp.status===200)
{
document.getElementById('b').innerHTML=xmlHttp.responseText;
}
else
{
document.getElementById('b').innerHTML="Waiting";
}
};
xmlHttp.open("post", "see_frm_DB.jsp", true);
xmlHttp.send();
}
</script>
<style>
.ui-widget { font-family: Lucida Grande, Lucida Sans, Arial, sans-serif; font-size: 0.6em; }
</style>
</head>
<body>
<div id="a">
<table>
<tr>
<td><label>Date Request received
</label> </td>
<td><input type='text' class='datepicker' name='date1' id="date1"></td>
<td><label>Date Request received
</label> </td>
<td><input type='text' class='datepicker' name='date2' id="date2"></td>
<td><input type="button" id="button" name="button" value="submit" onclick="getUsers();"></td>
</tr>
</table>
</div>
<div id="b">
</div>
</body>
</html>
並且連接如下。
<%--
Document : index
Created on : Aug 19, 2013, 8:07:29 PM
Author : U0138039
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="DBCon.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
try{
String a=request.getParameter("date1");
String b=request.getParameter("date2");
out.println(a);
out.println(b);
stmt=conn.createStatement();
sql="select * from [Sheet1$] where [Date Request received] between '"+a+"' and '"+b+"'";
out.print(sql);
rs=stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
int count = rsmd.getColumnCount();
conn.commit();
stmt.close();
conn.close();
%>
<table border="1">
<tr>
<%
// The column count starts from 1
for (int i = 1; i < columnCount + 1; i++) {
String name = rsmd.getColumnName(i);
// Do stuff with name%>
<td nowrap> <%
out.print(name);%></td>
<%
}%>
</tr>
<%
while(rs.next())
{
%>
<tr>
<%
for (int i=1; i<count; i++) {%>
<td>
<%=rs.getString(i)%> <%}%>
<%
}
}
catch(Exception e)
{
out.print(e);
}
%>
</td>
</tr>
</table>
%>
</body>
</html>
當我試圖運行這個程序時,我得到了下面的錯誤。實際上,這些值沒有得到通過。
null null select * from [Sheet1$] where [Date Request received] between 'null' and 'null'java.sql.SQLException: [Microsoft][ODBC Excel Driver] Data type mismatch in criteria expression. %>
請讓我知道如何解決此問題。
感謝
謝謝@Jonathan這工作,但你能告訴我,我怎麼形成該網址PLZ。謝謝 – user2423959
當然,傳遞給send()的字符串是一個標準的「查詢字符串」。它是由&s加入的key = value對,例如。鍵1 =值&鍵2 =值&KEY3 =值3。查詢字符串將被Java理解,因此您可以使用request.getParameter([param name])獲取您的值。 –
非常感謝你:) – user2423959