teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

追記

2016/06/21 01:56

投稿

l_l_l_l_l_l_l_l
l_l_l_l_l_l_l_l

スコア38

title CHANGED
File without changes
body CHANGED
@@ -148,7 +148,7 @@
148
148
  ```
149
149
 
150
150
  ###追記
151
- javaファイルを下記のしたところ下記のエラーが出てしまいました
151
+ javaファイルを変更まし下記のエラーが出てしまいました
152
152
 
153
153
  ↓ ↓ ↓ ↓ ↓
154
154
  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

1

追記

2016/06/21 01:56

投稿

l_l_l_l_l_l_l_l
l_l_l_l_l_l_l_l

スコア38

title CHANGED
File without changes
body CHANGED
@@ -45,135 +45,7 @@
45
45
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
46
46
 
47
47
  ```
48
- ###jsp
49
- ```
50
- <%@ page contentType="text/html; charset=UTF-8"
51
- import="java.sql.*,javax.naming.*,javax.sql.*,java.text.*"%>
52
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
53
- <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
54
48
 
55
-
56
- <html>
57
-
58
-
59
- <sql:setDataSource var="db" driver="com.mysql.jdbc.Driver"
60
- url="jdbc:mysql://localhost/Library" user="root" password="" />
61
-
62
- <sql:query var="rs1" dataSource="${db}">
63
- select * from user
64
- </sql:query>
65
- <head>
66
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
67
-
68
- <title>ユーザ管理画面</title>
69
- </head>
70
- <body>
71
- <h2>ユーザー管理画面</h2>
72
-
73
- <form method="POST" action="user_edit">
74
- ユーザーID
75
- <select name="user_no">
76
- <c:forEach var="row" items="${rs1.rows}">
77
- <option value=${row.user_no}>${row.user_id}</option>
78
- </c:forEach>
79
- </select>
80
- <br>
81
- 名前(姓)
82
- <input type="text" name="first_name" size="30">
83
- 名前(名)
84
- <input type="text" name="last_name" size="30">
85
- <br>
86
- カナ(姓)
87
- <input type="text" name="first_name_kana" size="30">
88
- カナ(名)
89
- <input type="text" name="last_name_kana" size="30">
90
- <br>
91
- ID
92
- <input type="text" name="user_id" size="30">
93
- パスワード
94
- <input type="password" name="password" size="30">
95
- <br><br>
96
-
97
- <input style="color:white;
98
- background-color:D57200;" type="submit" value="更新"/>
99
-
100
- </form>
101
- <c:if test="${!empty requestScope['errorMessage']}">
102
- <div>${requestScope['errorMessage']}</div>
103
- </c:if>
104
- <h3>ユーザリスト</h3>
105
- <table border="1" width=70%>
106
- <tr>
107
- <th>ユーザNo</th>
108
- <th>名前(姓)</th>
109
- <th>名前(名)</th>
110
-
111
- <th>カナ(姓)</th>
112
- <th>カナ(名)</th>
113
-
114
- <th>ID</th>
115
- <th>パスワード</th>
116
- </tr>
117
- <%
118
-
119
- Connection con = null;
120
- PreparedStatement ps = null;
121
- String sql = null;
122
- ResultSet rs = null;
123
- try{
124
- InitialContext initContext = new InitialContext();
125
- DataSource ds = (DataSource) initContext.lookup("java:comp/env/jdbc/Library");
126
- con = ds.getConnection();
127
- sql = "SELECT user_no,first_name,last_name,first_name_kana,last_name_kana,user_id,password FROM user";
128
-
129
- // SELECT命令の準備
130
- ps = con.prepareStatement(sql);
131
-
132
- // UPDATE命令を実行
133
- rs = ps.executeQuery();
134
- // 結果セットの内容を順に出力
135
- while(rs.next()){
136
-
137
- %>
138
-
139
- <tr>
140
- <td height=70><%=rs.getString("user_no") %></td>
141
- <td height=70><%=rs.getString("first_name") %></td>
142
- <td height=70><%=rs.getString("last_name") %></td>
143
- <td height=70><%=rs.getString("first_name_kana") %></td>
144
- <td height=70><%=rs.getString("last_name_kana") %></td>
145
- <td height=70><%=rs.getString("user_id") %></td>
146
- <td height=70><%=rs.getString("password") %></td>
147
-
148
- <%
149
- }
150
- }catch(Exception e){
151
- throw new ServletException(e);
152
-
153
- }finally{
154
- try{
155
- if(rs != null){rs.close();}
156
- if(rs != null){ps.close();}
157
- if(rs != null){con.close();}
158
- }catch(Exception e){}
159
-
160
- }
161
- %>
162
- </table>
163
- <form action="kanri_mypage.jsp">
164
- <input style="color:white;
165
- background-color:D57200;" type="submit" value="TOPページ">
166
- </form>
167
- <form action="user_kanri.jsp">
168
- <input style="color:white;
169
- background-color:D57200;" type="submit" value="戻る">
170
-
171
-
172
- </form>
173
- </body>
174
- </html>
175
- ```
176
-
177
49
  ###servlet
178
50
  ```
179
51
  package servlet;
@@ -199,6 +71,7 @@
199
71
  protected void doPost(HttpServletRequest request,
200
72
  HttpServletResponse response) throws ServletException, IOException {
201
73
  request.setCharacterEncoding("UTF-8");
74
+ String userId = request.getParameter("user_id");
202
75
 
203
76
  Connection con = null;
204
77
  PreparedStatement ps = null;
@@ -221,9 +94,8 @@
221
94
  DataSource ds = (DataSource) initContext
222
95
  .lookup("java:comp/env/jdbc/Library");
223
96
  con = ds.getConnection();
224
- // SQL
97
+ //
225
- sql = "UPDATE user SET (first_name,last_name,first_name_kana,last_name_kana,"
98
+ sql = "UPDATE user SET (first_name,last_name,first_name_kana,last_name_kana,user_id,password)=(?,?,?,?,?,?) WHERE user_id=?";
226
- + "user_id,password)=(?,?,?,?,?,?) WHERE user_id=?";
227
99
 
228
100
  // UPDATE命令の準備
229
101
  ps = con.prepareStatement(sql);
@@ -234,6 +106,7 @@
234
106
  ps.setString(4, request.getParameter("last_name_kana"));
235
107
  ps.setString(5, request.getParameter("user_id"));
236
108
  ps.setString(6, request.getParameter("password"));
109
+ ps.setString(7, userId);
237
110
 
238
111
  // UPDATE命令を実行
239
112
  ps.executeUpdate();
@@ -272,4 +145,49 @@
272
145
 
273
146
  }
274
147
 
275
- ```
148
+ ```
149
+
150
+ ###追記
151
+ javaファイルを下記のしたところ下記のエラーが出てしまいました
152
+
153
+ ↓ ↓ ↓ ↓ ↓
154
+ 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
155
+ type 例外レポート
156
+
157
+ メッセージ 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
158
+
159
+ 説明 The server encountered an internal error that prevented it from fulfilling this request.
160
+
161
+ 例外
162
+
163
+ 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
164
+ servlet.user_edit.doPost(user_edit.java:69)
165
+ javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
166
+ javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
167
+ org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
168
+ 原因
169
+
170
+ 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
171
+ sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
172
+ sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
173
+ sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
174
+ java.lang.reflect.Constructor.newInstance(Constructor.java:422)
175
+ com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
176
+ com.mysql.jdbc.Util.getInstance(Util.java:387)
177
+ com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
178
+ com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
179
+ com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
180
+ com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
181
+ com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
182
+ com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
183
+ com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
184
+ com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
185
+ com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
186
+ com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
187
+ com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
188
+ org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97)
189
+ org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97)
190
+ servlet.user_edit.doPost(user_edit.java:62)
191
+ javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
192
+ javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
193
+ org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)