現在練習がてらecサイトを作成しております。
使用言語はjava、フレームワークはstruts2です。
複数の商品を購入した際に購入した商品のデータをDB上に保存したいのですが
どうも一つ目しか登録されてないようです。
BuyItemConfirmAction.java
1public class BuyItemConfirmAction extends ActionSupport implements SessionAware{ 2 3 public Map<String, Object> session; 4 private BuyItemCompleteDAO buyItemCompleteDAO = new BuyItemCompleteDAO(); 5 public String execute() throws SQLException{ 6 7 8 9 buyItemCompleteDAO.buyItemInfo( 10 11 session.get("noteId").toString(), 12 session.get("login_user_id").toString(), 13 session.get("notePrice").toString(), 14 session.get("noteCount").toString(), 15 session.get("pay").toString()); 16 17 18 19 buyItemCompleteDAO.buyItemInfo( 20 21 session.get("caseId").toString(), 22 session.get("login_user_id").toString(), 23 session.get("casePrice").toString(), 24 session.get("caseCount").toString(), 25 session.get("pay").toString()); 26 String result = SUCCESS; 27 return result; 28} 29 30 31 32 33 34 35 @Override 36 public void setSession(Map<String, Object> session){ 37 this.session = session; 38 } 39}
buyItemCompleteDAO
1public class BuyItemCompleteDAO { 2 private DBConnector dbConnector = new DBConnector(); 3 private Connection connection = dbConnector.getConnection(); 4 private DateUtil dateUtil = new DateUtil(); 5 private String sql = "INSERT INTO user_buy_item_transaction(item_transaction_id, total_price, total_count,user_master_id,pay,insert_date) VALUES(?,?,?,?,?,?)"; 6 7 8 9 public void buyItemInfo(String item_transaction_id,String user_master_id, String total_price, String total_count, String pay) throws SQLException{ 10 try{ 11 PreparedStatement preparedStatement = connection.prepareStatement(sql); 12 preparedStatement.setString(1, item_transaction_id); 13 preparedStatement.setString(2, total_price); 14 preparedStatement.setString(3, total_count); 15 preparedStatement.setString(4, user_master_id); 16 preparedStatement.setString(5, pay); 17 preparedStatement.setString(6, dateUtil.getDate()); 18 preparedStatement.execute(); 19 }catch(Exception e){ 20 e.printStackTrace(); 21 }finally{ 22 connection.close(); 23 } 24 } 25}
buyItemComfirmActionで
buyItemInfoメソッド二回、商品別で使用したのにDBには一個目の商品しか登録されてませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。