每当我尝试在表单中插入值时,都会出错...
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:'field list'com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException中的未知列'regno':'字段列表'中的未知列'regno' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在com.mysql.jdbc.Util.handleNewInstance(Util.java:404) 在com.mysql.jdbc.Util.getInstance(Util.java:387) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939) 在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) 在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) 在com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478) 在com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625) 在com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547) 在com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1541) 在com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2605) 在com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1469) 在org.apache.jsp.insertRegister_jsp._jspService(insertRegister_jsp.java:96) 在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) 在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:310) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 在java.lang.Thread.run(Thread.java:748)
我的JSP文件registerVehicles.jsp是......
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Example</title>
</head>
<body>
<form method="post" action="insertRegister.jsp">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">Register New Vehicle</th>
</tr>
</thead>
<tbody>
<tr>
<td>Vehicle Registration Number</td>
<td><input type="text" name="vrn" value="" /></td>
</tr>
<tr>
<td>Manufacturer</td>
<td><input type="text" name="maker" value="" /></td>
</tr>
<tr>
<tr>
<td>Model</td>
<td><input type="text" name="model" value="" /></td>
</tr>
<tr>
<td>Manufactured Date</td>
<td><input type="date" name="mfd" value="" /></td>
</tr>
<tr>
<td>Fuel Type</td>
<td><input type="text" name="ft" value="" /></td>
</tr>
<td><input type="submit" value="submit" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
insertRegister.jsp
<%@ page import ="java.sql.*" %>
<%@page import="java.io.*, java.util.*,java.text.*"%>
<%
String vrn=request.getParameter("vrn");
String maker=request.getParameter("maker");
String model=request.getParameter("model");
String mfd=request.getParameter("mfd");
String ft=request.getParameter("ft");
java.util.Date date = Calendar.getInstance().getTime();
DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy ");
String currDate = dateFormat.format(date);
Calendar c = Calendar.getInstance();
c.setTime(new java.util.Date()); // Now use today date.
c.add(Calendar.DATE, +90);
String validDate = dateFormat.format(c.getTime());
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/puc", "root", "root");
Statement st=conn.createStatement();
int i=st.executeUpdate("insert into login(regno,maker,model,made_year,fuel_type,curr_date,vaalid_to)"+"values('"+vrn+"','"+maker+"','"+model+"','"+mfd+"','"+ft+"','"+currDate+"','"+ validDate +"')");
out.println("Data is successfully inserted!");
}
catch(Exception e)
{
System.out.print(e);
e.printStackTrace();
}
%>
有人可以帮我找到这个例外的原因吗?
答案 0 :(得分:2)
错误消息Unknown column 'regno' in 'field list'
表示该列login
中不存在该列。
您输入的列名称错误,或者表格的架构错误或者根本不存在。
答案 1 :(得分:0)
错误清晰可见。名为“login”的表没有名为“regno”的列。