###前提・実現したいこと
度々の質問失礼します。
表題にも表記してありますが、
java.sql.SQLException: No value specified for parameter 7
がよく分かりません。
下記にもソースを記載いたしますが、
7つ目のパラメータがないはずなのに
このようなエラーが出てしまいます。
###エラーメッセージ
HTTPステータス 500 - java.sql.SQLException: No value specified for parameter 7 type 例外レポート メッセージ java.sql.SQLException: No value specified for parameter 7 説明 The server encountered an internal error that prevented it from fulfilling this request. 例外 javax.servlet.ServletException: java.sql.SQLException: No value specified for parameter 7 servlet.user_edit.doPost(user_edit.java:68) javax.servlet.http.HttpServlet.service(HttpServlet.java:644) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 原因 java.sql.SQLException: No value specified for parameter 7 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2205) com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2185) com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2052) com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009) com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994) org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97) org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97) servlet.user_edit.doPost(user_edit.java:61) javax.servlet.http.HttpServlet.service(HttpServlet.java:644) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
###servlet
package servlet; import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import javax.naming.InitialContext; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.sql.DataSource; @WebServlet("/user_edit") public class user_edit extends HttpServlet { private static final long serialVersionUID = 1L; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String userId = request.getParameter("user_id"); Connection con = null; PreparedStatement ps = null; String sql = null; ResultSet rs = null; // セッションを取得する HttpSession session = request.getSession(); // 変数の初期化 boolean userResult = false; if (session.getAttribute("userResult") != null) { userResult = (boolean) session.getAttribute("userResult"); } if (userResult) { try { // データベースの接続を確立 InitialContext initContext = new InitialContext(); DataSource ds = (DataSource) initContext .lookup("java:comp/env/jdbc/Library"); con = ds.getConnection(); // sql = "UPDATE user SET (first_name,last_name,first_name_kana,last_name_kana,user_id,password)=(?,?,?,?,?,?) WHERE user_id=?"; // UPDATE命令の準備 ps = con.prepareStatement(sql); // UPDATE命令にポストデータの内容をセット ps.setString(1, request.getParameter("first_name")); ps.setString(2, request.getParameter("last_name")); ps.setString(3, request.getParameter("first_name_kana")); ps.setString(4, request.getParameter("last_name_kana")); ps.setString(5, request.getParameter("user_id")); ps.setString(6, request.getParameter("password")); ps.setString(7, userId); // UPDATE命令を実行 ps.executeUpdate(); // UPDATE命令後の画面遷移 this.getServletContext().getRequestDispatcher("/user_edit.jsp") .forward(request, response); } catch (Exception e) { throw new ServletException(e); } finally { try { if (rs != null) { rs.close(); } if (ps != null) { ps.close(); } if (con != null) { con.close(); } } catch (Exception e) { } } } else { // エラーメッセージをリクエスト格納 request.setAttribute("errorMessage", "ログインが行われていません。"); // ログイン画面遷移 this.getServletContext().getRequestDispatcher("/Login.jsp") .forward(request, response); } } }
###追記
javaファイルを変更しましたら下記のエラーが出てしまいました
↓ ↓ ↓ ↓ ↓
HTTPステータス 500 - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(first_name,last_name,first_name_kana,last_name_kana,user_id,password)=('aa','aa' at line 1
type 例外レポート
メッセージ com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(first_name,last_name,first_name_kana,last_name_kana,user_id,password)=('aa','aa' at line 1
説明 The server encountered an internal error that prevented it from fulfilling this request.
例外
javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(first_name,last_name,first_name_kana,last_name_kana,user_id,password)=('aa','aa' at line 1
servlet.user_edit.doPost(user_edit.java:69)
javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
原因
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(first_name,last_name,first_name_kana,last_name_kana,user_id,password)=('aa','aa' at line 1
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:422)
com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
com.mysql.jdbc.Util.getInstance(Util.java:387)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97)
org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97)
servlet.user_edit.doPost(user_edit.java:62)
javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/21 01:30
2016/06/21 01:52
2016/06/21 01:57
2016/06/21 02:12
2016/06/21 02:21