gpt4 book ai didi

mysql - 使用tomcat+JSP+JDBC删除MySQL列时eclipse错误 “com.mysql.jdbc.exceptions.MySQLSyntaxErrorException”

转载 作者:行者123 更新时间:2023-11-29 21:02:28 27 4
gpt4 key购买 nike

我对 Servlet 的经验有限,我想像这样单击按钮 AllDelete this ,但是在eclipse中出现错误:

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 '-6,6' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3124)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1149)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1262)
at com.newsmanager.dao.NewsDao.getNewsList(NewsDao.java:92)
at com.newsmanager.servlet.NewsServlet.doPost(NewsServlet.java:75)
at com.newsmanager.servlet.NewsServlet.doGet(NewsServlet.java:21)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

Servlet Java 代码:

else if ("allDelete".equals(oprate)) {
String[] deleteId = request.getParameterValues("deleteId");
if (deleteId != null) {
//the parameter might have more than one value, use getParameterValues(java.lang.String).
//And getParameterValues returns a String[];22
for (String string : deleteId) {
Integer Did = Integer.valueOf(string);
NewsDao.deleteNewsBYId(Did);

}
}
response.sendRedirect("NewsServlet");

}

JSP代码:

<input type="submit" value="AllDelete" />
<input type="hidden" id="oprate" name="oprate" value="allDelete" />
<td align="center"><input type="checkbox" name="deleteId" value="${news.newsId}" /></td>

我在网上找了好久。但没有用。请帮忙或尝试给出一些如何实现这一目标的想法

NewsDao.java 的部分代码

public List<News> getNewsList(Integer pageNumber, Integer pageSize) {
List<News> NewsList = new ArrayList<News>();
conn = DbConn.getconn();
try {
int startSize = (pageNumber - 1) * pageSize;
String sql = "select * from news limit " + startSize + "," + pageSize;
st = conn.createStatement();
rs = st.executeQuery(sql);

最佳答案

鉴于错误

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 '-6,6' at line 1

以及显示的代码,您正在尝试执行查询

select * from news limit -6,6

syntax for limit LIMIT {[offset,] row_count | row_count OFFSET offset} 。偏移量(也不行计数)不允许使用负值,因为这会导致您在第一行之前请求行(这当然是不可能的)。因此,MySQL 语法要求您提供无符号整数值,提供负值是语法错误。

关于mysql - 使用tomcat+JSP+JDBC删除MySQL列时eclipse错误 “com.mysql.jdbc.exceptions.MySQLSyntaxErrorException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37097193/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com