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

質問編集履歴

16

DAOクラスの94行目から96行目でutil.Dateをsql.Dateに変換しました。

2021/12/15 07:19

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -26,7 +26,7 @@
26
26
  import java.sql.ResultSet;
27
27
  import java.sql.SQLException;
28
28
  import java.sql.Time;
29
- import java.sql.Date;
29
+ import java.util.Date;
30
30
  import java.util.ArrayList;
31
31
  import java.util.List;
32
32
  import java.util.Properties;
@@ -107,13 +107,17 @@
107
107
 
108
108
  pstmt = myConn.prepareStatement(sql);
109
109
  pstmt.setInt(1, btd.getId());
110
+ Date date = btd.getDate();
111
+ long timeInMilliSeconds = date.getTime();
112
+ java.sql.Date date1 = new java.sql.Date(timeInMilliSeconds);
110
- pstmt.setDate(2, btd.getDate());
113
+ pstmt.setDate(2, date1);
111
114
  pstmt.setString(3, btd.getStoreName());
112
115
  pstmt.setString(4, btd.getProductName());
113
116
  pstmt.setString(5, btd.getProductType());
114
117
  pstmt.setInt(6, btd.getPrice());
115
118
  // SQL文発行
116
119
  pstmt.executeUpdate();
120
+ System.out.println("Suucessfully added");
117
121
  pstmt.close();
118
122
 
119
123
  //rowsCount = pstmt.executeUpdate(sql);

15

BudgetTrackerDao更新

2021/12/15 07:19

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -26,7 +26,7 @@
26
26
  import java.sql.ResultSet;
27
27
  import java.sql.SQLException;
28
28
  import java.sql.Time;
29
- import java.util.Date;
29
+ import java.sql.Date;
30
30
  import java.util.ArrayList;
31
31
  import java.util.List;
32
32
  import java.util.Properties;
@@ -47,7 +47,7 @@
47
47
  // get db properties
48
48
  Properties props = new Properties();
49
49
  props.load(new FileInputStream(
50
- "/home/user/git/BudgetTrackerCui/BudgetTrackerCui/sql/config_budgettracker.properties"));
50
+ "/home/yosuke/git/BudgetTrackerCui/BudgetTrackerCui/sql/config_budgettracker.properties"));
51
51
 
52
52
  String user = props.getProperty("user");
53
53
  String password = props.getProperty("password");
@@ -107,7 +107,7 @@
107
107
 
108
108
  pstmt = myConn.prepareStatement(sql);
109
109
  pstmt.setInt(1, btd.getId());
110
- pstmt.setDate(2, (java.sql.Date) btd.getDate());
110
+ pstmt.setDate(2, btd.getDate());
111
111
  pstmt.setString(3, btd.getStoreName());
112
112
  pstmt.setString(4, btd.getProductName());
113
113
  pstmt.setString(5, btd.getProductType());

14

エラー内容 2021/12/15 15:49更新

2021/12/15 06:53

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -3,9 +3,11 @@
3
3
  何故JDBCではエラーが起きるのか、ヒントがあればご教示頂けますと幸いです。
4
4
  String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE (?,?,?,?,?,?)";
5
5
 
6
- エラー内容 2021/12/15 15:31
6
+ エラー内容 2021/12/15 15:49
7
7
  ```ここに言語を入力
8
- Exception in thread "main" java.lang.ClassCastException: class java.util.Date cannot be cast to class java.sql.Date (java.util.Date is in module java.base of loader 'bootstrap'; java.sql.Date is in module java.sql of loader 'platform')
8
+ Exception in thread "main" java.lang.Error: Unresolved compilation problem:
9
+ The method setDate(int, java.sql.Date) in the type PreparedStatement is not applicable for the arguments (int, java.util.Date)
10
+
9
11
  at BudgetTrackerCui/com.jdbc.budgettracker.dao.BudgetTrackerDao.insertIntoTable(BudgetTrackerDao.java:93)
10
12
  at BudgetTrackerCui/com.jdbc.budgettracker.main.BudgetTrackerMain.main(BudgetTrackerMain.java:130)
11
13
  ```

13

BudgetTrackerMain.javaも一部記載

2021/12/15 06:49

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -218,7 +218,72 @@
218
218
  }
219
219
 
220
220
  ```
221
+ BudgetTrackerMain.java
222
+ ```ここに言語を入力
223
+ package com.jdbc.budgettracker.main;
221
224
 
225
+ import java.io.FileNotFoundException;
226
+ import java.io.IOException;
227
+ import java.sql.SQLException;
228
+ import java.util.Date;
229
+ import java.text.ParseException;
230
+ import java.text.SimpleDateFormat;
231
+ import java.util.HashMap;
232
+ import java.util.List;
233
+ import java.util.Map;
234
+ import java.util.Scanner;
235
+
236
+ import com.jdbc.budgettracker.core.BudgetTrackerDto;
237
+ import com.jdbc.budgettracker.dao.BudgetTrackerDao;
238
+
239
+ public class BudgetTrackerMain {
240
+
241
+ 一部省略
242
+
243
+ switch (initialNumInt) {
244
+
245
+ case 2:
246
+ // Insert
247
+ int insertcannerInt = 0;
248
+ System.out.println("You chose " + initialSwitchMap.get(2));
249
+ budgetTrackerDto = new BudgetTrackerDto();
250
+
251
+ Scanner insertScanner = new Scanner(System.in);
252
+ System.out.print("Input an ID: ");
253
+ int insertScannerInt = insertScanner.nextInt();
254
+ budgetTrackerDto.setId(insertScannerInt);
255
+
256
+ System.out.print("Input Date (yyyy-MM-dd): ");
257
+ String insertScannerStr = insertScanner.next();
258
+ Date insertDate=(Date) new SimpleDateFormat("yyyy-MM-dd").parse(insertScannerStr);
259
+ budgetTrackerDto.setDate(insertDate);
260
+
261
+ System.out.print("Input a store name: ");
262
+ insertScannerStr = insertScanner.next();
263
+ budgetTrackerDto.setStoreName(insertScannerStr);
264
+
265
+ System.out.print("Input a product name: ");
266
+ insertScannerStr = insertScanner.next();
267
+ budgetTrackerDto.setProductName(insertScannerStr);
268
+
269
+ System.out.print("Input a product type: ");
270
+ insertScannerStr = insertScanner.next();
271
+ budgetTrackerDto.setProductType(insertScannerStr);
272
+
273
+ System.out.print("Input price: ");
274
+ insertScannerStr = insertScanner.next();
275
+ insertcannerInt = Integer.parseInt(insertScannerStr);
276
+ budgetTrackerDto.setPrice(insertcannerInt);
277
+
278
+ budgetTrackerDao = new BudgetTrackerDao();
279
+ budgetTrackerDao.insertIntoTable(budgetTrackerDto);
280
+
281
+ }
282
+
283
+ }
284
+ }
285
+ ```
286
+
222
287
  画像 2021/12/15/11:49
223
288
  ![![イメージ説明](023e9f1da0bd0eb74ad4625964ededcf.png)](7963446809efa5fd7c31cdd56cb9dd98.png)
224
289
 

12

BudgetTrackerDto.javaを修正

2021/12/15 06:46

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -141,6 +141,7 @@
141
141
  ```
142
142
  BudgetTrackerDto.java
143
143
  ```ここに言語を入力
144
+
144
145
  package com.jdbc.budgettracker.core;
145
146
 
146
147
  import java.util.Date;
@@ -214,8 +215,10 @@
214
215
  this.price = price;
215
216
  }
216
217
 
217
- }```
218
+ }
218
219
 
220
+ ```
221
+
219
222
  画像 2021/12/15/11:49
220
223
  ![![イメージ説明](023e9f1da0bd0eb74ad4625964ededcf.png)](7963446809efa5fd7c31cdd56cb9dd98.png)
221
224
 

11

BudgetTrackerDto.javaを追加

2021/12/15 06:37

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -139,6 +139,83 @@
139
139
 
140
140
  }
141
141
  ```
142
+ BudgetTrackerDto.java
143
+ ```ここに言語を入力
144
+ package com.jdbc.budgettracker.core;
145
+
146
+ import java.util.Date;
147
+
148
+ public class BudgetTrackerDto {
149
+ private int id;
150
+ private Date date;
151
+ private String storeName;
152
+ private String productName;
153
+ private String productType;
154
+ private int price;
155
+
156
+ public BudgetTrackerDto() {
157
+ }
158
+
159
+ public BudgetTrackerDto(int id, Date date, String storeName, String productName, String productType, int price) {
160
+ super();
161
+ this.id = id;
162
+ this.date = date;
163
+ this.storeName = storeName;
164
+ this.productName = productName;
165
+ this.productType = productType;
166
+ this.price = price;
167
+ }
168
+
169
+ public int getId() {
170
+ return id;
171
+ }
172
+
173
+ public void setId(int id) {
174
+ this.id = id;
175
+ }
176
+
177
+ public Date getDate() {
178
+ return date;
179
+ }
180
+
181
+ public void setDate(Date insertDate) {
182
+ this.date = insertDate;
183
+ }
184
+
185
+ public String getStoreName() {
186
+ return storeName;
187
+ }
188
+
189
+ public void setStoreName(String storeName) {
190
+ this.storeName = storeName;
191
+ }
192
+
193
+ public String getProductName() {
194
+ return productName;
195
+ }
196
+
197
+ public void setProductName(String productName) {
198
+ this.productName = productName;
199
+ }
200
+
201
+ public String getProductType() {
202
+ return productType;
203
+ }
204
+
205
+ public void setProductType(String productType) {
206
+ this.productType = productType;
207
+ }
208
+
209
+ public int getPrice() {
210
+ return price;
211
+ }
212
+
213
+ public void setPrice(int price) {
214
+ this.price = price;
215
+ }
216
+
217
+ }```
218
+
142
219
  画像 2021/12/15/11:49
143
220
  ![![イメージ説明](023e9f1da0bd0eb74ad4625964ededcf.png)](7963446809efa5fd7c31cdd56cb9dd98.png)
144
221
 

10

エラー内容 2021/12/15 15:31追記

2021/12/15 06:36

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -3,10 +3,11 @@
3
3
  何故JDBCではエラーが起きるのか、ヒントがあればご教示頂けますと幸いです。
4
4
  String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE (?,?,?,?,?,?)";
5
5
 
6
- エラー内容 2021/12/15
6
+ エラー内容 2021/12/15 15:31
7
7
  ```ここに言語を入力
8
- Exception in thread "main" java.lang.ClassCastException: class com.mysql.cj.jdbc.StatementImpl cannot be cast to class java.sql.PreparedStatement (com.mysql.cj.jdbc.StatementImpl is in unnamed module of loader 'app'; java.sql.PreparedStatement is in module java.sql of loader 'platform')
9
- at BudgetTrackerCui/com.jdbc.budgettracker.dao.BudgetTrackerDao.insertIntoTable(BudgetTrackerDao.java:82)
8
+ Exception in thread "main" java.lang.ClassCastException: class java.util.Date cannot be cast to class java.sql.Date (java.util.Date is in module java.base of loader 'bootstrap'; java.sql.Date is in module java.sql of loader 'platform')
9
+ at BudgetTrackerCui/com.jdbc.budgettracker.dao.BudgetTrackerDao.insertIntoTable(BudgetTrackerDao.java:93)
10
+ at BudgetTrackerCui/com.jdbc.budgettracker.main.BudgetTrackerMain.main(BudgetTrackerMain.java:130)
10
11
  ```
11
12
 
12
13
 

9

93行目をpstmt.setDate(2, (java.sql.Date) btd.getDate());に変更

2021/12/15 06:31

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -23,6 +23,7 @@
23
23
  import java.sql.ResultSet;
24
24
  import java.sql.SQLException;
25
25
  import java.sql.Time;
26
+ import java.util.Date;
26
27
  import java.util.ArrayList;
27
28
  import java.util.List;
28
29
  import java.util.Properties;
@@ -43,7 +44,7 @@
43
44
  // get db properties
44
45
  Properties props = new Properties();
45
46
  props.load(new FileInputStream(
46
- "/home/yosuke/git/BudgetTrackerCui/BudgetTrackerCui/sql/config_budgettracker.properties"));
47
+ "/home/user/git/BudgetTrackerCui/BudgetTrackerCui/sql/config_budgettracker.properties"));
47
48
 
48
49
  String user = props.getProperty("user");
49
50
  String password = props.getProperty("password");
@@ -86,9 +87,9 @@
86
87
  }
87
88
 
88
89
 
89
- public int insertIntoTable(BudgetTrackerDto budgetTrackerDto) throws SQLException {
90
+ public int insertIntoTable(BudgetTrackerDto btd) throws SQLException {
90
91
  int rowsCount = 0;
91
- btd = new BudgetTrackerDto();
92
+
92
93
  PreparedStatement pstmt;
93
94
  try {
94
95
  // DBに接続
@@ -103,7 +104,7 @@
103
104
 
104
105
  pstmt = myConn.prepareStatement(sql);
105
106
  pstmt.setInt(1, btd.getId());
106
- pstmt.setTime(2, (Time) btd.getDate());
107
+ pstmt.setDate(2, (java.sql.Date) btd.getDate());
107
108
  pstmt.setString(3, btd.getStoreName());
108
109
  pstmt.setString(4, btd.getProductName());
109
110
  pstmt.setString(5, btd.getProductType());

8

画像「2021/12/15/12:21」を添付

2021/12/15 06:29

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -138,4 +138,7 @@
138
138
  }
139
139
  ```
140
140
  画像 2021/12/15/11:49
141
- ![![イメージ説明](023e9f1da0bd0eb74ad4625964ededcf.png)](7963446809efa5fd7c31cdd56cb9dd98.png)
141
+ ![![イメージ説明](023e9f1da0bd0eb74ad4625964ededcf.png)](7963446809efa5fd7c31cdd56cb9dd98.png)
142
+
143
+ 画像 2021/12/15/12:21
144
+ ![イメージ説明](9e2c388c8c09173d78b5d794aac14219.png)

7

画像を挿入しました。

2021/12/15 03:22

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -136,4 +136,6 @@
136
136
  }
137
137
 
138
138
  }
139
- ```
139
+ ```
140
+ 画像 2021/12/15/11:49
141
+ ![![イメージ説明](023e9f1da0bd0eb74ad4625964ededcf.png)](7963446809efa5fd7c31cdd56cb9dd98.png)

6

90行目から96行目を更新

2021/12/15 02:49

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -93,7 +93,7 @@
93
93
  try {
94
94
  // DBに接続
95
95
  myConn = BudgetTrackerDao.getConnection();
96
-  //pstmt = (PreparedStatement) myConn.createStatement();
96
+ // pstmt = (PreparedStatement) myConn.createStatement();
97
97
 
98
98
  // String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE('"
99
99
  // + btd.getId() + "','" + btd.getDate() + "','" + btd.getStoreName() + "','" + btd.getProductName() + "','" + btd.getProductType()
@@ -102,14 +102,14 @@
102
102
  String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE (?,?,?,?,?,?)";
103
103
 
104
104
  pstmt = myConn.prepareStatement(sql);
105
- (pstmt).setInt(1, btd.getId());
105
+ pstmt.setInt(1, btd.getId());
106
- (pstmt).setTime(2, (Time) btd.getDate());
106
+ pstmt.setTime(2, (Time) btd.getDate());
107
- (pstmt).setString(3, btd.getStoreName());
107
+ pstmt.setString(3, btd.getStoreName());
108
- (pstmt).setString(4, btd.getProductName());
108
+ pstmt.setString(4, btd.getProductName());
109
- (pstmt).setString(5, btd.getProductType());
109
+ pstmt.setString(5, btd.getProductType());
110
- (pstmt).setInt(6, btd.getPrice());
110
+ pstmt.setInt(6, btd.getPrice());
111
111
  // SQL文発行
112
- pstmt.executeUpdate(sql);
112
+ pstmt.executeUpdate();
113
113
  pstmt.close();
114
114
 
115
115
  //rowsCount = pstmt.executeUpdate(sql);

5

82行目をコメントアウト

2021/12/15 02:42

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -93,7 +93,7 @@
93
93
  try {
94
94
  // DBに接続
95
95
  myConn = BudgetTrackerDao.getConnection();
96
- pstmt = (PreparedStatement) myConn.createStatement();
96
+  //pstmt = (PreparedStatement) myConn.createStatement();
97
97
 
98
98
  // String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE('"
99
99
  // + btd.getId() + "','" + btd.getDate() + "','" + btd.getStoreName() + "','" + btd.getProductName() + "','" + btd.getProductType()

4

エラー内容更新

2021/12/15 02:37

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -3,11 +3,13 @@
3
3
  何故JDBCではエラーが起きるのか、ヒントがあればご教示頂けますと幸いです。
4
4
  String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE (?,?,?,?,?,?)";
5
5
 
6
- エラー内容
6
+ エラー内容 2021/12/15
7
7
  ```ここに言語を入力
8
- java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?,?,?,?)' at line 1
8
+ Exception in thread "main" java.lang.ClassCastException: class com.mysql.cj.jdbc.StatementImpl cannot be cast to class java.sql.PreparedStatement (com.mysql.cj.jdbc.StatementImpl is in unnamed module of loader 'app'; java.sql.PreparedStatement is in module java.sql of loader 'platform')
9
+ at BudgetTrackerCui/com.jdbc.budgettracker.dao.BudgetTrackerDao.insertIntoTable(BudgetTrackerDao.java:82)
9
10
  ```
10
11
 
12
+
11
13
  BudgetTrackerDao.java
12
14
  ```ここに言語を入力
13
15
  package com.jdbc.budgettracker.dao;

3

PreparedStatementに統一

2021/12/15 02:25

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -20,7 +20,6 @@
20
20
  import java.sql.PreparedStatement;
21
21
  import java.sql.ResultSet;
22
22
  import java.sql.SQLException;
23
- import java.sql.Statement;
24
23
  import java.sql.Time;
25
24
  import java.util.ArrayList;
26
25
  import java.util.List;
@@ -31,9 +30,10 @@
31
30
  public class BudgetTrackerDao {
32
31
  BudgetTrackerDto btd;
33
32
  private Connection myConn;
34
- private Statement mySmt;
33
+ private PreparedStatement mySmt;
35
34
 
36
- private static final String SQL = "select * from budget_table;";
35
+ private static final String SELECTALL = "select * from budget_table;";
36
+ // private static final String SELECTBYSTORENAME = "select * from budget_table where store name = ?;";
37
37
 
38
38
  private static Connection getConnection() {
39
39
 
@@ -41,7 +41,7 @@
41
41
  // get db properties
42
42
  Properties props = new Properties();
43
43
  props.load(new FileInputStream(
44
- "/home/user/git/BudgetTrackerCui/BudgetTrackerCui/sql/config_budgettracker.properties"));
44
+ "/home/yosuke/git/BudgetTrackerCui/BudgetTrackerCui/sql/config_budgettracker.properties"));
45
45
 
46
46
  String user = props.getProperty("user");
47
47
  String password = props.getProperty("password");
@@ -54,10 +54,12 @@
54
54
  }
55
55
  }
56
56
 
57
+ // select all
57
58
  public List<BudgetTrackerDto> selectAll() throws FileNotFoundException, IOException {
58
59
  List<BudgetTrackerDto> budgetList = new ArrayList<>();
59
60
 
60
- try (Connection conn = BudgetTrackerDao.getConnection(); PreparedStatement ps = conn.prepareStatement(SQL)) {
61
+ try (Connection conn = BudgetTrackerDao.getConnection();
62
+ PreparedStatement ps = conn.prepareStatement(SELECTALL)) {
61
63
 
62
64
  try (ResultSet rs = ps.executeQuery()) {
63
65
  while (rs.next()) {
@@ -81,31 +83,34 @@
81
83
  return budgetList;
82
84
  }
83
85
 
84
- // Insert
86
+
85
87
  public int insertIntoTable(BudgetTrackerDto budgetTrackerDto) throws SQLException {
86
88
  int rowsCount = 0;
87
89
  btd = new BudgetTrackerDto();
88
- Statement pstmt;
90
+ PreparedStatement pstmt;
89
91
  try {
90
92
  // DBに接続
91
93
  myConn = BudgetTrackerDao.getConnection();
92
- pstmt = myConn.createStatement();
94
+ pstmt = (PreparedStatement) myConn.createStatement();
93
95
 
94
96
  // String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE('"
95
97
  // + btd.getId() + "','" + btd.getDate() + "','" + btd.getStoreName() + "','" + btd.getProductName() + "','" + btd.getProductType()
96
98
  // + "','" + btd.getPrice() + "')";
97
99
 
98
- String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE (?,?,?,?,?,?)";
100
+ String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE (?,?,?,?,?,?)";
101
+
99
102
  pstmt = myConn.prepareStatement(sql);
100
- ((PreparedStatement) pstmt).setInt(1, btd.getId());
103
+ (pstmt).setInt(1, btd.getId());
101
- ((PreparedStatement) pstmt).setTime(2, (Time) btd.getDate());
104
+ (pstmt).setTime(2, (Time) btd.getDate());
102
- ((PreparedStatement) pstmt).setString(3, btd.getStoreName());
105
+ (pstmt).setString(3, btd.getStoreName());
103
- ((PreparedStatement) pstmt).setString(4, btd.getProductName());
106
+ (pstmt).setString(4, btd.getProductName());
104
- ((PreparedStatement) pstmt).setString(5, btd.getProductType());
107
+ (pstmt).setString(5, btd.getProductType());
105
- ((PreparedStatement) pstmt).setInt(6, btd.getPrice());
108
+ (pstmt).setInt(6, btd.getPrice());
109
+ // SQL文発行
106
110
  pstmt.executeUpdate(sql);
107
111
  pstmt.close();
108
112
 
113
+ //rowsCount = pstmt.executeUpdate(sql);
109
114
  } catch (SQLException e) {
110
115
  System.out.println("Errorが発生しました!\n" + e + "\n");
111
116
  } finally {

2

SQL文内の全角スペースを削除しました。

2021/12/15 02:20

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -95,8 +95,7 @@
95
95
  // + btd.getId() + "','" + btd.getDate() + "','" + btd.getStoreName() + "','" + btd.getProductName() + "','" + btd.getProductType()
96
96
  // + "','" + btd.getPrice() + "')";
97
97
 
98
- String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) "
98
+ String sql = "INSERT INTO budget_table(id,Date,StoreName, ProductName, ProductType, Price) " + "VALUE (?,?,?,?,?,?)";
99
- + "VALUE (?,?,?,?,?,?)";
100
99
  pstmt = myConn.prepareStatement(sql);
101
100
  ((PreparedStatement) pstmt).setInt(1, btd.getId());
102
101
  ((PreparedStatement) pstmt).setTime(2, (Time) btd.getDate());

1

不要だった2回目のexecuteUpdateを削除

2021/12/15 01:25

投稿

Yakusugi
Yakusugi

スコア123

title CHANGED
File without changes
body CHANGED
@@ -107,8 +107,6 @@
107
107
  pstmt.executeUpdate(sql);
108
108
  pstmt.close();
109
109
 
110
- // SQL文発行
111
- rowsCount = pstmt.executeUpdate(sql);
112
110
  } catch (SQLException e) {
113
111
  System.out.println("Errorが発生しました!\n" + e + "\n");
114
112
  } finally {