MySQL语法错误异常:

MySQLSyntaxErrorException:

每当我尝试在表单中插入值时,它都会出错...

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'regno' in 'field list'com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'regno' in 'field list' 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) at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) at com.mysql.jdbc.Util.getInstance(Util.java:387) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547) at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1541) at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2605) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1469) at org.apache.jsp.insertRegister_jsp._jspService(insertRegister_jsp.java:96) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at 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) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at 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) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at 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();
}
%>

谁能帮我找出这个异常的原因?

错误消息 Unknown column 'regno' in 'field list' 表示 table login 中不存在该列。 您输入的列名有误,或者您的 table 架构错误,或者根本不存在。

错误很明显。您的名为 "login" 的 table 没有名为 "regno" 的列。