質問編集履歴

1

コード、エラーの追加

2017/01/20 05:13

投稿

mashumaro0628
mashumaro0628

スコア19

test CHANGED
File without changes
test CHANGED
@@ -7,3 +7,465 @@
7
7
  実行はできるんですがエクリプスの例外エラーの画面に飛んでしまいます。
8
8
 
9
9
  経験者の方、ご指摘いただけますか。
10
+
11
+ ###前提・実現したいこと
12
+
13
+ ここに質問したいことを詳細に書いてください
14
+
15
+ (例)PHP(CakePHP)で●●なシステムを作っています。
16
+
17
+ ■■な機能を実装中に以下のエラーメッセージが発生しました。
18
+
19
+
20
+
21
+ ###発生している問題・エラーメッセージ
22
+
23
+
24
+
25
+ ```
26
+
27
+ 例外レポート
28
+
29
+
30
+
31
+ メッセージ An exception occurred processing JSP page /index.jsp at line 156
32
+
33
+
34
+
35
+ 153: Statement st2=conn2.createStatement();
36
+
37
+ 154: //HTMLから入力された、商品ID、単価、購入量、割引値をインサート
38
+
39
+ 155: String sql2 = "INSERT INTO product(product_id,product_tanka,product_quantity,product_discount) VALUES("+productID+","+price2+","+quantity2+","+disCount+")";
40
+
41
+ 156: st2.execute(sql2);
42
+
43
+ 157: st2.close();
44
+
45
+ 158: conn2.close();
46
+
47
+ 159: %>
48
+
49
+
50
+
51
+ 原因
52
+
53
+ javax.servlet.ServletException:
54
+
55
+ 原因
56
+
57
+ com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have
58
+
59
+
60
+
61
+ ###該当のソースコード
62
+
63
+ ```jsp
64
+
65
+ <%@ page contentType="text/html; charset=utf-8" import="java.sql.*" %>
66
+
67
+ <!doctype html>
68
+
69
+ <html>
70
+
71
+ <head>
72
+
73
+ <meta charset="utf-8">
74
+
75
+ <style>
76
+
77
+ div#main{
78
+
79
+ margin: 50px;
80
+
81
+ padding: 0;
82
+
83
+ border: 5px solid black;
84
+
85
+ height: 500px;
86
+
87
+ width: 540px;
88
+
89
+ }
90
+
91
+ div#button{
92
+
93
+ margin: 5px 10px 10px 290px;
94
+
95
+ border: 5px solid black;
96
+
97
+ height: 480px;
98
+
99
+ width: 230px;
100
+
101
+ }
102
+
103
+ div.list{
104
+
105
+ margin: -500px 10px 5px 5px;
106
+
107
+ border: 5px solid black;
108
+
109
+ height: 250px;
110
+
111
+ width: 270px;
112
+
113
+ overflow-y: scroll;
114
+
115
+ }
116
+
117
+ table.list{
118
+
119
+ height: 250px;
120
+
121
+ width: 245px;
122
+
123
+ }
124
+
125
+ th{
126
+
127
+ height: 20px;
128
+
129
+ }
130
+
131
+ input{
132
+
133
+ width:50px;
134
+
135
+ }
136
+
137
+ div.output{
138
+
139
+ margin: 1px 10px 5px 5px;
140
+
141
+ padding: 0;
142
+
143
+ border: 5px solid black;
144
+
145
+ height: 215px;
146
+
147
+ width: 270px;
148
+
149
+ overflow-y:scroll;
150
+
151
+ }
152
+
153
+ table.output{
154
+
155
+ height: 215px;
156
+
157
+ width: 252px;
158
+
159
+ }
160
+
161
+ tr{
162
+
163
+ height: 5px;
164
+
165
+ }
166
+
167
+ a{
168
+
169
+ margin: 0 50px;
170
+
171
+ padding: 0;
172
+
173
+ }
174
+
175
+ input.output{
176
+
177
+ height: auto;
178
+
179
+ width: 75px;
180
+
181
+ }
182
+
183
+ td{
184
+
185
+ width:70px;
186
+
187
+ }
188
+
189
+ </style>
190
+
191
+ </head>
192
+
193
+ <body>
194
+
195
+
196
+
197
+ <script type="text/javascript">
198
+
199
+ function showClock1() {
200
+
201
+ var nowTime = new Date();
202
+
203
+ var nowMonth = nowTime.getMonth();
204
+
205
+ var nowDate = nowTime.getDate();
206
+
207
+ var nowHour = nowTime.getHours();
208
+
209
+ var nowMin = nowTime.getMinutes();
210
+
211
+ var nowSec = nowTime.getSeconds();
212
+
213
+ var msg = nowHour + ":" + nowMin + ":" + nowSec ;
214
+
215
+ document.getElementById("time").innerHTML = msg;
216
+
217
+ }
218
+
219
+ setInterval('showClock1()',1000);
220
+
221
+
222
+
223
+
224
+
225
+ </script>
226
+
227
+ <form method="post" action="index.jsp">
228
+
229
+ <select name="product" >
230
+
231
+ <option value="T">Tシャツ</option>
232
+
233
+ <option value="S">パンツ</option>
234
+
235
+ <option value="B">ボトム</option>
236
+
237
+ <option value="J">ジャケット</option>
238
+
239
+ </select>
240
+
241
+ <select name="product" >
242
+
243
+ <option value="10">10%</option>
244
+
245
+ <option value="30">30%</option>
246
+
247
+ <option value="50">50%</option>
248
+
249
+ <option value="70">70%</option>
250
+
251
+ </select>
252
+
253
+ <input type="text" value="" name="quantity">
254
+
255
+ <input type="submit" value="登録">
256
+
257
+ </form>
258
+
259
+ <div id="main">
260
+
261
+ <div id="button"></div>
262
+
263
+ <div class="list">
264
+
265
+ <%
266
+
267
+ int i=0; //添え字
268
+
269
+ String quantity="";
270
+
271
+ String product="";
272
+
273
+ String disCount="";
274
+
275
+ if(i==1){
276
+
277
+ quantity = request.getParameter("quantity");//htmlからの購入量の受け取り
278
+
279
+ product = request.getParameter("product"); //htmlからの商品名の受け取り
280
+
281
+ disCount = request.getParameter("discount");//htmlからの割引率の受け取り
282
+
283
+ }
284
+
285
+ i++;
286
+
287
+ int price2=0; //単価
288
+
289
+ String productID=""; //商品ID
290
+
291
+ int disCount2=0; //割引率
292
+
293
+ int quantity2=0; //量
294
+
295
+ //割引変数を判断して整数型に変換
296
+
297
+ if(disCount.equals("10")){
298
+
299
+ disCount2 = 10;
300
+
301
+ }else if(disCount.equals("30")){
302
+
303
+ disCount2 = 30;
304
+
305
+ }else if(disCount.equals("50")){
306
+
307
+ disCount2 = 50;
308
+
309
+ }else if(disCount.equals("70")){
310
+
311
+ disCount2 = 70;
312
+
313
+ }
314
+
315
+ //購入量の受け取り
316
+
317
+ if(quantity.equals("1")){
318
+
319
+ quantity2 = 1;
320
+
321
+ }else if(quantity.equals("2")){
322
+
323
+ quantity2 = 2;
324
+
325
+ }else if(quantity.equals("3")){
326
+
327
+ quantity2 = 3;
328
+
329
+ }else if(quantity.equals("4")){
330
+
331
+ quantity2 = 4;
332
+
333
+ }
334
+
335
+ //商品名から判断し商品IDと単価を整数型変数に代入
336
+
337
+ if(product.equals("T")){
338
+
339
+ price2 = 1000;
340
+
341
+ productID = "0001";
342
+
343
+ }else if(product.equals("S")){
344
+
345
+ price2 = 2000;
346
+
347
+ productID = "0002";
348
+
349
+ }else if(product.equals("B")){
350
+
351
+ price2 = 3000;
352
+
353
+ productID = "0003";
354
+
355
+ }else if(product.equals("J")){
356
+
357
+ price2 = 4000;
358
+
359
+ productID = "0004";
360
+
361
+ }
362
+
363
+ //データベースを開いてコネクション確立
364
+
365
+ Class.forName("com.mysql.jdbc.Driver");
366
+
367
+ Connection conn2=DriverManager.getConnection("jdbc:mysql://localhost/test?" ,"root","admin");
368
+
369
+ Statement st2=conn2.createStatement();
370
+
371
+ //HTMLから入力された、商品ID、単価、購入量、割引値をインサート
372
+
373
+ String sql2 = "INSERT INTO product(product_id,product_tanka,product_quantity,product_discount) VALUES("+productID+","+price2+","+quantity2+","+disCount+")";
374
+
375
+ st2.execute(sql2);
376
+
377
+ st2.close();
378
+
379
+ conn2.close();
380
+
381
+ %>
382
+
383
+ <table border="1">
384
+
385
+ <%
386
+
387
+ //データベースを開いてコネクション確立
388
+
389
+ Class.forName("com.mysql.jdbc.Driver");
390
+
391
+ Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test?" ,"root","admin");
392
+
393
+ Statement st=conn.createStatement();
394
+
395
+ ResultSet res = st2.executeQuery("select * from product");
396
+
397
+ //データベースからの表示
398
+
399
+ while(res.next()){
400
+
401
+ out.println("<tr>");
402
+
403
+ out.println("<td>" + res.getString("product_id") + "</td>");
404
+
405
+ out.println("<td>" + res.getString("product_tanka") + "</td>");
406
+
407
+ out.println("<td>" + res.getString("product_quantity") + "</td>");
408
+
409
+ out.println("<td>" + res.getString("product_discount") + "</td>");
410
+
411
+ out.println("</tr>");
412
+
413
+ }
414
+
415
+ //データベース閉じる
416
+
417
+ st.close();
418
+
419
+ conn.close();
420
+
421
+ %>
422
+
423
+ </table>
424
+
425
+ </div>
426
+
427
+ <div class="output">
428
+
429
+ <table border="1" class="output">
430
+
431
+ <tr><td colspan="5"><a id="time"></a></td><td>クレジット</td></tr>
432
+
433
+ <tr><td colspan="5" id="shokei">小計</td><td><input type="text" value="" class="output"></td></tr>
434
+
435
+ <tr><td colspan="5">お預かり</td><td>リボ</td></tr>
436
+
437
+ <tr><td colspan="5">合計</td><td><input type="text" value="" class="output"></td></tr>
438
+
439
+ <tr><td colspan="5">おつり</td><td>担当</td></tr>
440
+
441
+ <tr><td colspan="5">会員コード</td><td></td></tr>
442
+
443
+ <tr><td colspan="6">有効ポイント</td></tr>
444
+
445
+ <tr><td colspan="6">伝票番号</td></tr>
446
+
447
+ </table>
448
+
449
+ </div>
450
+
451
+ </div>
452
+
453
+ <button type="button" onclick="shokei()">小計</button>
454
+
455
+ </body>
456
+
457
+ </html>
458
+
459
+ ```
460
+
461
+
462
+
463
+ ###試したこと
464
+
465
+ データベースの項目名が間違っていないかの照らし合わせ
466
+
467
+
468
+
469
+ ###補足情報(言語/FW/ツール等のバージョンなど)
470
+
471
+ より詳細な情報