質問編集履歴
2
setString別に使ってない
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,12 +40,6 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
素人考えでは、date型のカラムに対してsetStringを使ってString型で
|
44
|
-
|
45
|
-
値を用意しているのが怪しいと思っているのですが…
|
46
|
-
|
47
|
-
|
48
|
-
|
49
43
|
以下、ソースコードです。
|
50
44
|
|
51
45
|
|
1
乗せるソース間違え
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,25 +54,381 @@
|
|
54
54
|
|
55
55
|
|
56
56
|
|
57
|
-
|
57
|
+
insert文を実行する処理
|
58
|
-
|
59
|
-
|
60
58
|
|
61
59
|
```
|
62
60
|
|
61
|
+
package servlet;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
import java.io.IOException;
|
66
|
+
|
67
|
+
import java.sql.Connection;
|
68
|
+
|
69
|
+
import java.sql.Date;
|
70
|
+
|
71
|
+
import java.sql.DriverManager;
|
72
|
+
|
73
|
+
import java.sql.PreparedStatement;
|
74
|
+
|
75
|
+
import java.sql.ResultSet;
|
76
|
+
|
77
|
+
import java.sql.SQLException;
|
78
|
+
|
79
|
+
import java.sql.Statement;
|
80
|
+
|
81
|
+
import java.util.ArrayList;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
import javax.servlet.RequestDispatcher;
|
86
|
+
|
87
|
+
import javax.servlet.ServletException;
|
88
|
+
|
89
|
+
import javax.servlet.ServletRequest;
|
90
|
+
|
91
|
+
import javax.servlet.annotation.WebServlet;
|
92
|
+
|
93
|
+
import javax.servlet.http.HttpServlet;
|
94
|
+
|
95
|
+
import javax.servlet.http.HttpServletRequest;
|
96
|
+
|
97
|
+
import javax.servlet.http.HttpServletResponse;
|
98
|
+
|
99
|
+
import javax.servlet.http.HttpSession;
|
100
|
+
|
101
|
+
import javax.xml.crypto.Data;
|
102
|
+
|
103
|
+
import model.*;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression;
|
108
|
+
|
109
|
+
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
@WebServlet("/AddSchedule")
|
114
|
+
|
115
|
+
public class AddSchedule extends HttpServlet {
|
116
|
+
|
117
|
+
private static final long serialVersionUID = 1L;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
String year;
|
126
|
+
|
127
|
+
String month;
|
128
|
+
|
129
|
+
String day;
|
130
|
+
|
131
|
+
String shour;
|
132
|
+
|
133
|
+
String sminute;
|
134
|
+
|
135
|
+
String ehour;
|
136
|
+
|
137
|
+
String eminute;
|
138
|
+
|
139
|
+
String plan;
|
140
|
+
|
141
|
+
String memo;
|
142
|
+
|
143
|
+
String parameter;
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
// parameterCHeckを呼び出したいがためだけにmonthインスタンスを生成.よき方法求む
|
148
|
+
|
149
|
+
Month m = new Month();
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
// パラメータが不正な値じゃないかチェック×2
|
154
|
+
|
155
|
+
parameter = request.getParameter("YEAR");
|
156
|
+
|
157
|
+
System.out.println("年は" + parameter);
|
158
|
+
|
159
|
+
year = m.stringParameterCheck(parameter);
|
160
|
+
|
161
|
+
parameter = request.getParameter("MONTH");
|
162
|
+
|
163
|
+
System.out.println("月は" + parameter);
|
164
|
+
|
165
|
+
month = m.stringParameterCheck(parameter);
|
166
|
+
|
167
|
+
parameter = request.getParameter("DAY");
|
168
|
+
|
169
|
+
System.out.println("日は" + parameter);
|
170
|
+
|
171
|
+
day = m.stringParameterCheck(parameter);
|
172
|
+
|
173
|
+
parameter = request.getParameter("SHOUR");
|
174
|
+
|
175
|
+
System.out.println("shourは" + parameter);
|
176
|
+
|
177
|
+
shour = m.stringParameterCheck(parameter);
|
178
|
+
|
179
|
+
parameter = request.getParameter("SMINUTE");
|
180
|
+
|
181
|
+
System.out.println("sminuteは" + parameter);
|
182
|
+
|
183
|
+
sminute = m.stringParameterCheck(parameter);
|
184
|
+
|
185
|
+
parameter = request.getParameter("EHOUR");
|
186
|
+
|
187
|
+
System.out.println("ehourは" + parameter);
|
188
|
+
|
189
|
+
ehour = m.stringParameterCheck(parameter);
|
190
|
+
|
191
|
+
parameter = request.getParameter("EMINUTE");
|
192
|
+
|
193
|
+
System.out.println("eminuteは" + parameter);
|
194
|
+
|
195
|
+
eminute = m.stringParameterCheck(parameter);
|
196
|
+
|
197
|
+
parameter = request.getParameter("PLAN");
|
198
|
+
|
199
|
+
System.out.println("planは" + parameter);
|
200
|
+
|
201
|
+
plan = m.stringParameterCheck(parameter);
|
202
|
+
|
203
|
+
parameter = request.getParameter("MEMO");
|
204
|
+
|
205
|
+
System.out.println("memoは" + parameter);
|
206
|
+
|
207
|
+
memo = m.stringParameterCheck(parameter);
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
// 日付が不正な値な時、パラメータ無しでCalendar.jspにリダイレクト
|
212
|
+
|
213
|
+
if (year.equals("") || month.equals("") || day.equals("")) {
|
214
|
+
|
215
|
+
response.sendRedirect("/CalendarJsp/Calendar.jsp");
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
// 0埋め
|
222
|
+
|
223
|
+
month = String.format("%02d", Integer.parseInt(month));
|
224
|
+
|
225
|
+
day = String.format("%02d", Integer.parseInt(day));
|
226
|
+
|
227
|
+
shour = String.format("%02d", Integer.parseInt(shour));
|
228
|
+
|
229
|
+
sminute = String.format("%02d", Integer.parseInt(shour));
|
230
|
+
|
231
|
+
ehour = String.format("%02d", Integer.parseInt(ehour));
|
232
|
+
|
233
|
+
eminute = String.format("%02d", Integer.parseInt(eminute));
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
// insert文のwhere旬に代入する値を準備
|
238
|
+
|
239
|
+
// sql実行のためにフォーマットを整る
|
240
|
+
|
241
|
+
String date_format = "'" + year + "-" + month + "-" + day ;
|
242
|
+
|
243
|
+
String date_query = date_format + " 00:00:00'";
|
244
|
+
|
245
|
+
String start_time_query =date_format + " " + shour + ":" + sminute + ":00'";
|
246
|
+
|
247
|
+
String end_time_query = date_format + " " + ehour + ":" + eminute + ":00'";
|
248
|
+
|
249
|
+
// 日付が指定されていない場合開始時間及び終了時間をnullで登録
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
if (shour.equals("") || sminute.equals("") || eminute.equals("") || ehour.equals("")) {
|
254
|
+
|
255
|
+
System.out.println("日付おかしいぞぉ");
|
256
|
+
|
257
|
+
start_time_query = null;
|
258
|
+
|
259
|
+
end_time_query = null;
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
System.out.println("おかしいといわれてる月の値は" + date_query);
|
266
|
+
|
267
|
+
System.out.println("おかしいといわれているはじまりの時間の値は" + start_time_query);
|
268
|
+
|
269
|
+
System.out.println("おかしいといわれているおわりの時間の値は" + end_time_query);
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
response.setContentType("text/html; charset=UTF-8");
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
Connection conn = null;
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
try {
|
282
|
+
|
283
|
+
// JDBCドライバを読み込み
|
284
|
+
|
285
|
+
Class.forName("oracle.jdbc.driver.OracleDriver");
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
// データベースへ接続
|
290
|
+
|
291
|
+
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.132:1521:xe", "stockuser", "moriara0029");
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
// insert文を準備
|
296
|
+
|
297
|
+
String sql = "insert into schedule (id,userid, scheduledate, starttime, endtime, schedule, schedulememo) values ( 1,2," + date_query + "," + start_time_query + "," + end_time_query + "," + "'" + plan + "'," + "'" +memo + "')";
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
System.out.println("実行するsqlはこれだ!" + sql);
|
302
|
+
|
303
|
+
PreparedStatement pstmt = conn.prepareStatement(sql);
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
// 実行
|
312
|
+
|
313
|
+
int num = pstmt.executeUpdate();
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
pstmt.close();
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
} catch (ClassNotFoundException e) {
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
e.printStackTrace();
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
} catch (SQLException e) {
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
e.printStackTrace();
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
} catch (Exception e) {
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
e.printStackTrace();
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
} finally {
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
try {
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
if (conn != null) {
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
conn.close();
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
} catch (SQLException e) {
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
e.printStackTrace();
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
//ただmonthから1ひきたかっただけなんだ…
|
380
|
+
|
381
|
+
int month_numeric_value = Integer.parseInt(month) - 1;
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
StringBuffer sb = new StringBuffer();
|
386
|
+
|
387
|
+
sb.append("/CalendarJsp/Calendar.jsp");
|
388
|
+
|
389
|
+
sb.append("?YEAR=");
|
390
|
+
|
391
|
+
sb.append(year);
|
392
|
+
|
393
|
+
sb.append("&MONTH=");
|
394
|
+
|
395
|
+
sb.append(month_numeric_value);
|
396
|
+
|
397
|
+
response.sendRedirect(new String(sb));
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
```
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
入力フォームであるjsp
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
```
|
414
|
+
|
415
|
+
<%@page import="java.util.Calendar"%>
|
416
|
+
|
63
417
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
64
418
|
|
65
419
|
pageEncoding="UTF-8"%>
|
66
420
|
|
67
|
-
<
|
421
|
+
<%@ page import="model.Month"%>
|
422
|
+
|
423
|
+
|
68
424
|
|
69
425
|
<html>
|
70
426
|
|
71
427
|
<head>
|
72
428
|
|
73
|
-
<meta
|
429
|
+
<meta charset=UTF-8">
|
74
|
-
|
430
|
+
|
75
|
-
<title>
|
431
|
+
<title>カレンダーの表示</title>
|
76
432
|
|
77
433
|
</head>
|
78
434
|
|
@@ -80,237 +436,317 @@
|
|
80
436
|
|
81
437
|
|
82
438
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
<
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
439
|
+
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
<%
|
444
|
+
|
445
|
+
Month month = new Month();
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
// パラメータ確認。値がない、不正な場合-999をセット
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
String year_parameter = request.getParameter("YEAR");
|
454
|
+
|
455
|
+
String month_parameter = request.getParameter("MONTH");
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
int year_now = month.intParameterCheck(year_parameter);
|
460
|
+
|
461
|
+
int month_now = month.intParameterCheck(month_parameter);
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
if (year_now == -999 || month_now == -999) {
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
//現在の年、月をセット
|
470
|
+
|
471
|
+
year_now = month.cal.get(Calendar.YEAR);
|
472
|
+
|
473
|
+
month_now = month.cal.get(Calendar.MONTH) + 1;
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
//12月の次は1月かつ次年度
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
if (month_now > 12) {
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
month_now = 1;
|
490
|
+
|
491
|
+
year_now++;
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
}
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
//逆もまた然り
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
if (month_now < 1) {
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
month_now = 12;
|
508
|
+
|
509
|
+
year_now--;
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
}
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
int date_now = month.cal.get(Calendar.DATE);
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
//monthインスタンスになんとなく現在の日時をセット
|
522
|
+
|
523
|
+
month.cal.set(Calendar.YEAR, year_now);
|
524
|
+
|
525
|
+
month.cal.set(Calendar.MONTH, month_now - 1);
|
526
|
+
|
527
|
+
month.cal.set(Calendar.DATE, 1);
|
528
|
+
|
529
|
+
%>
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
<a
|
534
|
+
|
535
|
+
href="/CalendarJsp/Calendar.jsp?YEAR=<%=year_now%>&MONTH=<%=month_now + 1%>">翌月</a> <%=year_now%>年<%=month_now%>月
|
536
|
+
|
537
|
+
<a
|
538
|
+
|
539
|
+
href="/CalendarJsp/Calendar.jsp?YEAR=<%=year_now%>&MONTH=<%=month_now - 1%>">前月</a>
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
<table border="1">
|
552
|
+
|
553
|
+
<tr>
|
554
|
+
|
555
|
+
<th>日</th>
|
556
|
+
|
557
|
+
<th>月</th>
|
558
|
+
|
559
|
+
<th>火</th>
|
560
|
+
|
561
|
+
<th>水</th>
|
562
|
+
|
563
|
+
<th>木</th>
|
564
|
+
|
565
|
+
<th>金</th>
|
566
|
+
|
567
|
+
<th>土</th>
|
568
|
+
|
569
|
+
</tr>
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
<!-- その月の最終日 -->
|
574
|
+
|
575
|
+
<%
|
576
|
+
|
577
|
+
int max_day = month.cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
578
|
+
|
579
|
+
%>
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
<!--1日の曜日 -->
|
584
|
+
|
585
|
+
<%
|
586
|
+
|
587
|
+
int start_index = month.cal.get(Calendar.DAY_OF_WEEK);
|
588
|
+
|
589
|
+
%>
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
<tr>
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
<!-- 1週目の1日までを空白で埋める -->
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
<%
|
604
|
+
|
605
|
+
for (int i = 1; i < start_index; i++) {
|
606
|
+
|
607
|
+
%>
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
<td> </td>
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
<%
|
622
|
+
|
623
|
+
}
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
//当月の最終日まで日付けを入れていく
|
628
|
+
|
629
|
+
for (int i = 1; i <= max_day; i++) {
|
630
|
+
|
631
|
+
%>
|
632
|
+
|
633
|
+
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
<td><a
|
638
|
+
|
639
|
+
href="/CalendarJsp/scheduleDetail.jsp?YEAR=<%=year_now%>&MONTH=<%=month_now%>&DAY=<%=i%>"><%=i%></a></td>
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
<%
|
646
|
+
|
647
|
+
month.cal.set(Calendar.DATE, i);
|
648
|
+
|
649
|
+
%>
|
650
|
+
|
651
|
+
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
<!-- 土曜日なら次の列へ -->
|
658
|
+
|
659
|
+
<%
|
660
|
+
|
661
|
+
if (Calendar.SATURDAY == month.cal.get(Calendar.DAY_OF_WEEK)) {
|
662
|
+
|
663
|
+
%>
|
664
|
+
|
665
|
+
|
666
|
+
|
667
|
+
</tr>
|
668
|
+
|
669
|
+
|
670
|
+
|
671
|
+
<%
|
672
|
+
|
673
|
+
}
|
674
|
+
|
675
|
+
%>
|
676
|
+
|
677
|
+
|
678
|
+
|
679
|
+
|
680
|
+
|
681
|
+
|
682
|
+
|
683
|
+
<%
|
684
|
+
|
685
|
+
}
|
686
|
+
|
687
|
+
%>
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
<!-- 当月の最終日が土曜日じゃない時、土曜日まで余白を埋める -->
|
692
|
+
|
693
|
+
<%
|
694
|
+
|
695
|
+
System.out.println("日付最終日までのループが終わった時点での年は" + month.cal.get(month.cal.YEAR));
|
696
|
+
|
697
|
+
System.out.println("月は" + month.cal.get(month.cal.MONTH));
|
698
|
+
|
699
|
+
System.out.println("問題の日は" + month.cal.get(month.cal.DATE));
|
700
|
+
|
701
|
+
System.out.println("曜日は" + month.cal.get(month.cal.DAY_OF_WEEK));
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
if (month.cal.get(month.cal.DAY_OF_WEEK) < 7) {
|
706
|
+
|
707
|
+
System.out.println("ちっちぇぞぉ");
|
708
|
+
|
709
|
+
%>
|
710
|
+
|
711
|
+
|
712
|
+
|
713
|
+
<td>
|
714
|
+
|
715
|
+
<%
|
716
|
+
|
717
|
+
for (int count = month.cal.get(month.cal.DAY_OF_WEEK); count < 6; count++) {
|
718
|
+
|
719
|
+
|
720
|
+
|
721
|
+
System.out.println("空白をいれるよん");
|
722
|
+
|
723
|
+
%>
|
724
|
+
|
725
|
+
|
726
|
+
|
727
|
+
<td> </td>
|
728
|
+
|
729
|
+
<%
|
730
|
+
|
731
|
+
}
|
732
|
+
|
733
|
+
%>
|
734
|
+
|
735
|
+
|
736
|
+
|
737
|
+
</td>
|
738
|
+
|
739
|
+
<%
|
740
|
+
|
741
|
+
}
|
742
|
+
|
743
|
+
%>
|
744
|
+
|
745
|
+
|
746
|
+
|
747
|
+
</table>
|
748
|
+
|
749
|
+
</form>
|
314
750
|
|
315
751
|
|
316
752
|
|
@@ -319,251 +755,3 @@
|
|
319
755
|
</html>
|
320
756
|
|
321
757
|
```
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
insert文を実行する処理
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
```
|
332
|
-
|
333
|
-
package databaseTest;
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
import java.io.IOException;
|
338
|
-
|
339
|
-
import java.sql.Connection;
|
340
|
-
|
341
|
-
import java.sql.Date;
|
342
|
-
|
343
|
-
import java.sql.DriverManager;
|
344
|
-
|
345
|
-
import java.sql.PreparedStatement;
|
346
|
-
|
347
|
-
import java.sql.SQLException;
|
348
|
-
|
349
|
-
import java.text.ParseException;
|
350
|
-
|
351
|
-
import java.text.SimpleDateFormat;
|
352
|
-
|
353
|
-
import java.util.Locale;
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
import javax.servlet.ServletException;
|
358
|
-
|
359
|
-
import javax.servlet.annotation.WebServlet;
|
360
|
-
|
361
|
-
import javax.servlet.http.HttpServlet;
|
362
|
-
|
363
|
-
import javax.servlet.http.HttpServletRequest;
|
364
|
-
|
365
|
-
import javax.servlet.http.HttpServletResponse;
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
@WebServlet("/AddTest")
|
370
|
-
|
371
|
-
public class AddTest extends HttpServlet {
|
372
|
-
|
373
|
-
private static final long serialVersionUID = 1L;
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
// パラメータ取得
|
382
|
-
|
383
|
-
String year = request.getParameter("YEAR");
|
384
|
-
|
385
|
-
String month = request.getParameter("MONTH");
|
386
|
-
|
387
|
-
String day = request.getParameter("DAY");
|
388
|
-
|
389
|
-
String shour = request.getParameter("SHOUR");
|
390
|
-
|
391
|
-
String sminute = request.getParameter("SUMINUTE");
|
392
|
-
|
393
|
-
String ehour = request.getParameter("EHOUR");
|
394
|
-
|
395
|
-
String eminute = request.getParameter("EMINUTE");
|
396
|
-
|
397
|
-
String plan = request.getParameter("PLAN");
|
398
|
-
|
399
|
-
String memo = request.getParameter("MEMO");
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
// 0埋め
|
404
|
-
|
405
|
-
month = String.format("%02d", Integer.parseInt(month));
|
406
|
-
|
407
|
-
day = String.format("%02d", Integer.parseInt(day));
|
408
|
-
|
409
|
-
shour = String.format("%02d", Integer.parseInt(shour));
|
410
|
-
|
411
|
-
sminute = String.format("%02d", Integer.parseInt(sminute));
|
412
|
-
|
413
|
-
ehour = String.format("%02d", Integer.parseInt(ehour));
|
414
|
-
|
415
|
-
eminute = String.format("%02d", Integer.parseInt(eminute));
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
// insert文のwhere旬に代入する値を準備
|
420
|
-
|
421
|
-
// sql実行のためにフォーマットを整る
|
422
|
-
|
423
|
-
String date_format = "'" + year + "-" + month + "-" + day;
|
424
|
-
|
425
|
-
String date_query = date_format + " 00:00:00'";
|
426
|
-
|
427
|
-
String start_time_query = date_format + " " + shour + ":" + sminute + ":00'";
|
428
|
-
|
429
|
-
String end_time_query = date_format + " " + ehour + ":" + eminute + ":00'";
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
// 日付が指定されていない場合開始時間及び終了時間をnullで登録
|
434
|
-
|
435
|
-
if (shour.equals("") || sminute.equals("") || eminute.equals("") || ehour.equals("")) {
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
start_time_query = null;
|
440
|
-
|
441
|
-
end_time_query = null;
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
}
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
response.setContentType("text/html; charset=UTF-8");
|
452
|
-
|
453
|
-
Connection conn = null;
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
try {
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
// JDBCドライバを読み込み
|
462
|
-
|
463
|
-
Class.forName("oracle.jdbc.driver.OracleDriver");
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
// データベースへ接続
|
468
|
-
|
469
|
-
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.132:1521:xe", "stockuser", "moriara0029");
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
// insert文を準備
|
474
|
-
|
475
|
-
String sql = "insert into schedule (id,userid, scheduledate, starttime, endtime, schedule, schedulememo) values (?, ?, ?, ?, ?, ?,?)";
|
476
|
-
|
477
|
-
PreparedStatement pstmt = conn.prepareStatement(sql);
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
// where旬に置き換えていく
|
482
|
-
|
483
|
-
pstmt.setInt(1, 1);
|
484
|
-
|
485
|
-
pstmt.setInt(2, 2);
|
486
|
-
|
487
|
-
pstmt.setString(3, date_query);
|
488
|
-
|
489
|
-
pstmt.setString(4, start_time_query);
|
490
|
-
|
491
|
-
pstmt.setString(5, end_time_query);
|
492
|
-
|
493
|
-
pstmt.setString(6, plan);
|
494
|
-
|
495
|
-
pstmt.setString(7, memo);
|
496
|
-
|
497
|
-
// 実行
|
498
|
-
|
499
|
-
int num = pstmt.executeUpdate();
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
pstmt.close();
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
} catch (ClassNotFoundException e) {
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
e.printStackTrace();
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
} catch (SQLException e) {
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
e.printStackTrace();
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
} catch (Exception e) {
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
e.printStackTrace();
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
} finally {
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
try {
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
if (conn != null) {
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
conn.close();
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
}
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
} catch (SQLException e) {
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
e.printStackTrace();
|
556
|
-
|
557
|
-
}
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
}
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
}
|
566
|
-
|
567
|
-
}
|
568
|
-
|
569
|
-
```
|