Java 我的jsp页面未使用结果集rs=st.executeQuery()进行验证;
这是apache tomcat服务器异常。我在mysql中创建了一个“customers1”mysql表/视图。我在mysql表中没有问题,一切正常。我使用jsp,mysql和java。我的页面必须直接从SEFHTML.jsp页面到facultyentryform.jsp。每当我尝试提供新字段时,上面的以下代码必须保存在mysql服务器中您错过了条件之间的Java 我的jsp页面未使用结果集rs=st.executeQuery()进行验证;,java,mysql,jsp,Java,Mysql,Jsp,这是apache tomcat服务器异常。我在mysql中创建了一个“customers1”mysql表/视图。我在mysql表中没有问题,一切正常。我使用jsp,mysql和java。我的页面必须直接从SEFHTML.jsp页面到facultyentryform.jsp。每当我尝试提供新字段时,上面的以下代码必须保存在mysql服务器中您错过了条件之间的和: 87: Connection con = DriverManager.getConnection("jdbc:mysql://local
和
:
87: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
88: ResultSet rs;
89: Statement st = con.createStatement();
90: rs=st.executeQuery("SELECT * FROM customers1 WHERE RegistrationNumber='" + RegistrationNumber + "'Name='" + Name + "'Course='" + Course + "' and Batch='" + Batch + "'");
91: if (rs.next()) {
92: session.setAttribute("RegistrationNumber",RegistrationNumber);
93: session.setAttribute("Name",Name);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name='null'Course='null' and Batch='null'' at line 1
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:669)
org.apache.jsp.SEFHTML1_jsp._jspService(SEFHTML1_jsp.java:238)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name='null'Course='null' and Batch='null'' at line 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
org.apache.jsp.SEFHTML1_jsp._jspService(SEFHTML1_jsp.java:208)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
正如我所评论的:
不要在jsp中直接使用jdbc。了解三层体系结构了解防止SQL注入的准备语句您的查询不正确,这就是显示的错误:
您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解第1行com.MySQL.jdbc.SQLError.createSQLException(SQLError.java:936)中“Name='null'Course='null'和Batch='null'附近使用的正确语法
请使用“和”连接列名和值。是否要在所有列名之间添加?@koushikredy Yes必须是column name=value column name。。。。其中是像AND这样的逻辑运算符,或者,…我应该在所有列之间添加,还是它们的任何特定列。@Koushikredy抱歉,无法根据您所说的解决问题,但现在它不是指向下一页。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import ="java.sql.*" %>
<%@page import ="java.io.*" %>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Faculty Entry Form</title>
<label><b>FacultyID</b></label>
<input type="text" placeholder="Enter FacultyID" name="FacultyID" required>
<label><b>FacultyName</b></label>
<input type="text" placeholder="Enter FacultyName" name="FacultyName" required>
<label><b>Designation</b></label>
<input type="text" placeholder="Enter Designation" name="Designation" required>
</head>
<body>
<%
String FacultyID=request.getParameter("FacultyID");
String FacultyName=request.getParameter("FacultyName");
String Designation=request.getParameter("Designation");
Class.forName("com.mysql.jdbc.Driver");
ResultSet rs;
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
PreparedStatement st = con.prepareStatement("INSERT INTO customers2(FacultyID,FacultyName,Designation) VALUES(?,?,?)");
st.setString(1,FacultyID);
st.setString(2,FacultyName);
st.setString(3,Designation);
int i=st.executeUpdate();
if(i!=0)
{
response.sendRedirect("bookentryform.jsp");
out.print("Welcome");
}
else
{
response.sendRedirect("facultyentryform.jsp");
}
%>
</body>
</html>
87: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
88: ResultSet rs;
89: Statement st = con.createStatement();
90: rs=st.executeQuery("SELECT * FROM customers1 WHERE RegistrationNumber='" + RegistrationNumber + "'Name='" + Name + "'Course='" + Course + "' and Batch='" + Batch + "'");
91: if (rs.next()) {
92: session.setAttribute("RegistrationNumber",RegistrationNumber);
93: session.setAttribute("Name",Name);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name='null'Course='null' and Batch='null'' at line 1
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:669)
org.apache.jsp.SEFHTML1_jsp._jspService(SEFHTML1_jsp.java:238)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name='null'Course='null' and Batch='null'' at line 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
org.apache.jsp.SEFHTML1_jsp._jspService(SEFHTML1_jsp.java:208)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
rs=st.executeQuery("SELECT *
FROM customers1
WHERE RegistrationNumber='" + RegistrationNumber + "' AND Name='" + Name + "' AND Course='" + Course + "' and Batch='" + Batch + "'");