0
我從數據庫'Prison'中讀取的以前的JSP文件運行良好。但是,應該把值插入到數據庫中我的「add.jsp」文件顯示此異常:JSP-Access jdbc錯誤:插入到語句中 - 「查詢值和目標字段的數量不相同」
"SQLException: Number of query values and destination fields are not the same"
My MS Access2007, converted to **Access2003** Prison db with table 'Nominal' has 14 fields:
PNo(int), PName(str), Age(int), Address(str), Height(int), Weight(int), Health(str), Possessions(str), Occupation(str), Case(str), Sentence(str), From(str), To(str) and Parole(str).
在DB至今一直選擇類型使用的SQL查詢。但是,更改表的查詢會觸發異常。引號和逗號,名字都已經被徹底檢查過了,正如其他論壇所指出的那樣,但它們都很好。所以我們試圖捕捉異常並且變得更糟。它實際上顯示'添加記錄',但沒有。而是在tomcat7.exe cmd提示符中出現相同的錯誤消息。 我使用jdk1.6.0_21和 這裏是我的代碼的副本。希望有些朋友幫忙:
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
Connection con=null;
Statement stmt=null;
try
{
String url="jdbc:odbc:Prison";
con=DriverManager.getConnection(url);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
if(request.getParameter("action")!=null)
{
try
{
int PNo=Integer.parseInt(request.getParameter("PNo"));
String PName=request.getParameter("PName");
int Age=Integer.parseInt(request.getParameter("Age"));
String Address=request.getParameter("Address");
int Height=Integer.parseInt(request.getParameter("Height"));
int Weight=Integer.parseInt(request.getParameter("Weight"));
String Health=request.getParameter("Health");
String Possessions=request.getParameter("Possessions");
String Occupation=request.getParameter("Occupation");
String Case=request.getParameter("Case");
String Sentence=request.getParameter("Sentence");
String From=request.getParameter("From");
String To=request.getParameter("To");
String Parole=request.getParameter("Parole");
System.out.println(PNo);
String s="insert into Nominal values('" +PNo+ "','"+Possessions+ "','" +Occupation+ "','" +Case+ "','" +Sentence+ "','" +From+ "','" +To+ "','" +Parole+ "')";
stmt.executeUpdate(s);
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Success!</title>
</head>
<body>
<h1>Record Added</h1>
<a href="addp.html">Back</a>
</body>
</html>
<%
stmt.close();
con.close();
}
%>
請大家幫忙。