2020-06-05-----java.sql.SQLException: No value specified for parameter 3

Javaweb运行项目报错 No value specified for parameter 3

第三个参数没有值。但是我检查了n多次自己的代码,发现并没有第三个参数,也没有手误写的括号啥的,怎么改都是这个错误提示。但是最终的错误地方肯定在SQL语句里。

java.sql.SQLException: No value specified for parameter 3
执行sql语句失败
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1115)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
	at com.jdbc.DButil.DButil.update(DButil.java:128)
	at com.jdgl.service.JdService.updateRoom(JdService.java:315)
	at com.jdgl.servlet.UpdateRoomServlet.doPost(UpdateRoomServlet.java:28)
	at com.jdgl.servlet.UpdateRoomServlet.doGet(UpdateRoomServlet.java:18)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

有用的错误信息只有下面几句

java.sql.SQLException: No value specified for parameter 3
at com.jdbc.DButil.DButil.update(DButil.java:128)
	at com.jdgl.service.JdService.updateRoom(JdService.java:315)
	at com.jdgl.servlet.UpdateRoomServlet.doPost(UpdateRoomServlet.java:28)
	at com.jdgl.servlet.UpdateRoomServlet.doGet(UpdateRoomServlet.java:18)

刚开始我的SQL语句是

String sql = "update room set room_num=?,room_price=? where room_num=";

修改之后的SQL语句是

String sql = "update room set room_num=?,room_price=? where room_num="+roomNum;

原来是修改的房间号码没有传过来。
真的迷茫了好几天的错误。

最后想说的是,对于程序小白来建议在改错的时候可以多些几条输出语句来检测错误地方。

你可能感兴趣的:(JavaWeb)