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

質問編集履歴

3

**を消しました。

2021/02/04 11:40

投稿

mikannn
mikannn

スコア5

title CHANGED
File without changes
body CHANGED
@@ -50,13 +50,12 @@
50
50
  int newStockNo = (int) (new_stock_no.get(i.getPro_cd()));
51
51
  i.setStock_no(newStockNo);
52
52
  }
53
- ---
53
+
54
54
  //購入後の在庫更新のためのArrayList
55
- **ArrayList<Integer> remainingStockNo = new ArrayList<Integer>();**
55
+ ArrayList<Integer> remainingStockNo = new ArrayList<Integer>();
56
56
 
57
57
  //salesテーブルに更新するため。合計金額を入れるArrayList。
58
- **ArrayList<Integer> salesPrice = new ArrayList<Integer>();**
58
+ ArrayList<Integer> salesPrice = new ArrayList<Integer>();
59
- ---
60
59
 
61
60
  //--------------------------------------------------------------------------------------------------------------
62
61
  for (CartBean i : product_select_list) {
@@ -106,7 +105,7 @@
106
105
  ---
107
106
  //2.購入後のproductテーブル更新
108
107
  //④購入後の在庫更新(SalesDao.javaのメソッドを呼び、在庫数を更新する。)
109
- **pro_dao.remaining_stock_no_update(product_cd_list, remainingStockNo);**
108
+ pro_dao.remaining_stock_no_update(product_cd_list, remainingStockNo);
110
109
  ---
111
110
 
112
111
 
@@ -121,7 +120,7 @@
121
120
  //⑤Sales(購入テーブル)に格納する。
122
121
  //ユーザーID(user_id),商品コード( pro_cd),購入金額(product_sum_price)を入れる
123
122
  ---
124
- **sal_db.sales_db_insert(user_id, product_cd_list, salesPrice);**
123
+ sal_db.sales_db_insert(user_id, product_cd_list, salesPrice);
125
124
  ---
126
125
  //-------------------------------------------------------------------------------------------------------------------
127
126
  //product_select_listを消す←購入を続けるとき、履歴を消すため。
@@ -163,7 +162,7 @@
163
162
  //商品コード
164
163
  pstmt.setInt(2, pro_cd_list.get());
165
164
 
166
- pstmt.executeUpdate();**
165
+ pstmt.executeUpdate();
167
166
  }
168
167
  ---
169
168
  } catch (ClassNotFoundException ex) {

2

for文の括弧の位置をpstmt.executeUpdate();**の下に移動させました。

2021/02/04 11:40

投稿

mikannn
mikannn

スコア5

title CHANGED
File without changes
body CHANGED
@@ -162,8 +162,9 @@
162
162
  pstmt.setInt(1, remainingStockNo.get());
163
163
  //商品コード
164
164
  pstmt.setInt(2, pro_cd_list.get());
165
+
166
+ pstmt.executeUpdate();**
165
- }
167
+ }
166
- pstmt.executeUpdate();**
167
168
  ---
168
169
  } catch (ClassNotFoundException ex) {
169
170
  //例外の文をコンソールに出力。何行目にエラーが出てるかの説明。

1

コードの中のいらないものをけしました。下コードのfor文の中身を形を変えました。

2021/02/04 11:35

投稿

mikannn
mikannn

スコア5

title CHANGED
@@ -1,1 +1,1 @@
1
- ArrayList 多次元配列の作り方
1
+ 二つの配列を一つfor文で回す事はできますでしょうか。
body CHANGED
@@ -1,5 +1,4 @@
1
1
  ```Java
2
- クラスConfirmationServlet
3
2
  package controller;
4
3
 
5
4
  import java.io.IOException;
@@ -137,8 +136,7 @@
137
136
 
138
137
  ```
139
138
 
140
- ```Java 
139
+ ```Java
141
- クラスProductDaoより一部抜粋。
142
140
  //ConfirmationServletより、商品を判別するための商品コードと、残り在庫数を取ってくる。
143
141
  public void remaining_stock_no_update(ArrayList<Integer> product_cd_list, ArrayList<Integer> remainingStockNo) {
144
142
 
@@ -161,9 +159,9 @@
161
159
         for() {
162
160
  pstmt = con.prepareStatement("update product set stock_no = ? where pro_cd = ?");
163
161
  //残り在庫
164
- pstmt.setInt(1, remaining_stock_no);
162
+ pstmt.setInt(1, remainingStockNo.get());
165
163
  //商品コード
166
- pstmt.setInt(2, pro_cd);
164
+ pstmt.setInt(2, pro_cd_list.get());
167
165
  }
168
166
  pstmt.executeUpdate();**
169
167
  ---