前提・実現したいこと
閲覧いただき、ありがとうございます。
Eclipse,Springを使ってJAVAの勉強をしている(超)初心者です。
マスタメンテ画面で更新機能を作成しようとしています。
データベース(unit02.addressbook)はid(int),name(String),phone(String),address(String)の項目でなりたっています。
いざ更新ボタンを押下すると、下記のようなエラーがでてしまい、
どうもパラメタがうまくSQLに渡っていないように思えます。
どこに問題があるのかご教授いただけないでしょうか。
発生している問題・エラーメッセージ
HTTPステータス 500 - Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [update unit02.addressbook set name = ? , tel = ?, address = ? where id = ? ]; Can not issue data manipulation statements with executeQuery().; nested exception is java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
type 例外レポート
メッセージ Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [update unit02.addressbook set name = ? , tel = ?, address = ? where id = ? ]; Can not issue data manipulation statements with executeQuery().; nested exception is java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
該当のソースコード
java
1@Controller 2@RequestMapping(value = "/book") 3public class AddressBookController { 4---省略 5 private RecordManager recordManager; 6---省略 7 public AddressBookController(RecordManager recordManager) { 8 this.recordManager = recordManager; 9 } 10 @RequestMapping(value = "/start") //初期画面 11 public String init(AddressBookForm form, Model model) { 12 model.addAttribute("message", INIMSG); 13 return INIT; 14 } 15---省略 16 @RequestMapping(params = "reflection") //更新ボタン押下時 17 public String reflection(AddressBookForm form, Model model) { 18 Employee employee = new Employee(form.getId(), form.getName(), form.getPhone(), form.getAddress()); 19 recordManager.updateEmployee(form.getId(), form.getName(), form.getPhone(), form.getAddress()); 20 } 21---省略 22
java
1 public Employee updateEmployee(String id,String name, String phone, String address){ 2 System.out.println("para=" + id + name + phone + address); 3 try{ 4 return jdbcTemplate.queryForObject("update unit02.addressbook set name = ? , tel = ?, address = ? where id = ? ", 5 new Object[]{ name , phone , address, id }, 6 new RowMapper<Employee>() { 7 @Override 8 public Employee mapRow(ResultSet rs, int rowNum) throws SQLException { 9 Employee employee = new Employee("","","",""); 10 employee.setId(rs.getString("id")); 11 employee.setName(rs.getString("name")); 12 employee.setPhone(rs.getString("tel")); 13 employee.setAddress(rs.getString("address")); 14 return employee; 15 } 16 }); 17 } catch (IncorrectResultSizeDataAccessException e) { 18 System.out.println("data incorrect ERR"); 19 return null; 20 } 21 }
試したこと
- updateEmployeeクラスにFormからのパラメタは正しく渡っている。
- 同じ文法で Mysqlを実行すると正常に更新できる。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/05 04:43