質問編集履歴
1
ソース追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -152,40 +152,77 @@
|
|
152
152
|
<button type="submit">カートに入れる</button>
|
153
153
|
</form>
|
154
154
|
|
155
|
-
|
155
|
+
|
156
|
-
List<String> itemCode = new ArrayList<String>();
|
157
|
-
itemCode.add("A10000 ");
|
158
|
-
itemCode.add("B10000 ");
|
159
|
-
itemCode.add("C10000 ");
|
160
|
-
|
161
|
-
List<String> item = new ArrayList<String>();
|
162
|
-
item.add("ハンバーグ弁当 ");
|
163
|
-
item.add("野菜サラダ ");
|
164
|
-
item.add("野菜ジュース ");
|
165
|
-
|
166
|
-
List<String> price = new ArrayList<String>();
|
167
|
-
price.add("300");
|
168
|
-
price.add("200");
|
169
|
-
price.add("100");
|
170
|
-
--%>
|
171
|
-
<%--
|
172
|
-
<table>
|
173
|
-
<caption>商品一覧</caption>
|
174
|
-
<tr>
|
175
|
-
<th>商品コード</th><th>商品名</th><th>価格</th>
|
176
|
-
</tr>
|
177
|
-
<%
|
178
|
-
for(int i=0;i<itemCode.size();i++){
|
179
|
-
%>
|
180
|
-
<tr>
|
181
|
-
<td><%=itemCode.get(i) %></td><td><%=item.get(i) %></td><td><%=price.get(i) %></td>
|
182
|
-
</tr>
|
183
|
-
<%
|
184
|
-
}
|
185
|
-
%>
|
186
|
-
|
187
|
-
</table>
|
188
|
-
--%>
|
189
156
|
</body>
|
190
157
|
</html>
|
191
158
|
```
|
159
|
+
|
160
|
+
```dao
|
161
|
+
package model.dao;
|
162
|
+
|
163
|
+
import java.sql.Connection;
|
164
|
+
import java.sql.PreparedStatement;
|
165
|
+
import java.sql.ResultSet;
|
166
|
+
import java.sql.SQLException;
|
167
|
+
import java.util.ArrayList;
|
168
|
+
import java.util.List;
|
169
|
+
|
170
|
+
import model.entity.UserBean;
|
171
|
+
|
172
|
+
public class UserDAO {
|
173
|
+
|
174
|
+
/*
|
175
|
+
* ログイン認証
|
176
|
+
*
|
177
|
+
*/
|
178
|
+
public boolean login(String customer_id, String password) throws SQLException, ClassNotFoundException {
|
179
|
+
String sql = "SELECT * from m_customer WHERE customer_id=? AND password=?";
|
180
|
+
|
181
|
+
try (Connection con = ConnectionManager.getConnection(); PreparedStatement pstmt = con.prepareStatement(sql)) {
|
182
|
+
|
183
|
+
pstmt.setString(1, customer_id);
|
184
|
+
pstmt.setString(2, password);
|
185
|
+
|
186
|
+
ResultSet res = pstmt.executeQuery();
|
187
|
+
|
188
|
+
while (res.next()) {
|
189
|
+
return true;
|
190
|
+
}
|
191
|
+
|
192
|
+
}
|
193
|
+
|
194
|
+
return false;
|
195
|
+
}
|
196
|
+
|
197
|
+
// 商品一覧表示
|
198
|
+
public List<UserBean> itemAll() throws SQLException, ClassNotFoundException {
|
199
|
+
|
200
|
+
List<UserBean> list = new ArrayList<UserBean>();
|
201
|
+
|
202
|
+
// 商品名、価格を取得
|
203
|
+
String sql = "SELECT ja.item_nm, se.price, se.item_cd FROM shopping_db.m_sales_item se inner join shopping_db.m_jancode ja on se.jan_cd = ja.jan_cd";
|
204
|
+
|
205
|
+
try (Connection con = ConnectionManager.getConnection(); PreparedStatement pstmt = con.prepareStatement(sql)) {
|
206
|
+
|
207
|
+
ResultSet res = pstmt.executeQuery();
|
208
|
+
|
209
|
+
while (res.next()) {
|
210
|
+
String item = res.getString("item_nm");
|
211
|
+
int price = res.getInt("price");
|
212
|
+
String item_cd = res.getString("item_cd");
|
213
|
+
|
214
|
+
UserBean userbean = new UserBean();
|
215
|
+
userbean.setItem_nm(item);
|
216
|
+
userbean.setPrice(price);
|
217
|
+
userbean.setItem_cd(item_cd);
|
218
|
+
|
219
|
+
list.add(userbean);
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
return list;
|
226
|
+
}
|
227
|
+
```
|
228
|
+
|