質問編集履歴
3
テーブル定義、コードの追加を行いました
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
### 該当のソースコード
|
20
20
|
con = DriverManager.getConnection(
|
21
21
|
"jdbc:mysql://localhost:3306/local_db?useUnicode=true&characterEncoding=utf8", "root",
|
22
|
-
"
|
22
|
+
"id");
|
23
23
|
System.out.println("MySQLに接続できました。");
|
24
24
|
String sql = "delete from t_users where copcod= ? and empnum =? and knjnamsei =? and knjnammei =?";
|
25
25
|
PreparedStatement stmt = con.prepareStatement(sql);
|
@@ -30,4 +30,97 @@
|
|
30
30
|
stmt.setString(4, knjnammei);
|
31
31
|
```ここに言語名を入力
|
32
32
|
Java
|
33
|
+
```
|
34
|
+
|
35
|
+
CREATE TABLE `t_users` (
|
36
|
+
`copcod` varchar(4) NOT NULL,
|
37
|
+
`empnum` varchar(8) NOT NULL,
|
38
|
+
`knjnamsei` varchar(40) DEFAULT NULL,
|
39
|
+
`knjnammei` varchar(40) DEFAULT NULL,
|
40
|
+
PRIMARY KEY (`copcod`,`empnum`)
|
41
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
42
|
+
```ここに言語を入力
|
43
|
+
TABLE定義
|
44
|
+
``````ここに言語を入力
|
45
|
+
package MVC;
|
46
|
+
|
47
|
+
import java.io.IOException;
|
48
|
+
import java.sql.*;
|
49
|
+
|
50
|
+
import javax.servlet.ServletException;
|
51
|
+
|
52
|
+
public class UsersDelete {
|
53
|
+
private int result;
|
54
|
+
private String resultCopcod;
|
55
|
+
private String resultEmpnum;
|
56
|
+
private String resultKnjnamsei;
|
57
|
+
private String resultKnjnammei;
|
58
|
+
|
59
|
+
public String getresultDelreteCopcod() {
|
60
|
+
return this.resultCopcod;
|
61
|
+
}
|
62
|
+
|
63
|
+
public String getresultDelreteEmpnum() {
|
64
|
+
return this.resultEmpnum;
|
65
|
+
}
|
66
|
+
|
67
|
+
public String getresultDelreteKnjnamsei() {
|
68
|
+
return this.resultKnjnamsei;
|
69
|
+
}
|
70
|
+
|
71
|
+
public String getresultDelreteKnjnammei() {
|
72
|
+
return this.resultKnjnammei;
|
73
|
+
}
|
74
|
+
|
75
|
+
public int getResult() {
|
76
|
+
return this.result;
|
77
|
+
}
|
78
|
+
|
79
|
+
public void processing(String copcod, String empnum, String knjnamsei, String knjnammei)
|
80
|
+
throws ServletException, IOException {
|
81
|
+
|
82
|
+
Connection con = null;
|
83
|
+
try {
|
84
|
+
// JDBCドライバのロード - JDBC4.0(JDK1.6)以降は不要
|
85
|
+
Class.forName("com.mysql.jdbc.Driver");
|
86
|
+
// MySQLに接続
|
87
|
+
con = DriverManager.getConnection(
|
88
|
+
"jdbc:mysql://localhost:3306/local_db?useUnicode=true&characterEncoding=utf8", "root",
|
89
|
+
"id");
|
90
|
+
System.out.println("MySQLに接続できました。");
|
91
|
+
String sql = "delete from t_users where copcod= ? and empnum =? and knjnamsei =? and knjnammei =?";
|
92
|
+
PreparedStatement stmt = con.prepareStatement(sql);
|
93
|
+
|
94
|
+
stmt.setString(1, copcod);
|
95
|
+
stmt.setString(2, empnum);
|
96
|
+
stmt.setString(3, knjnamsei);
|
97
|
+
stmt.setString(4, knjnammei);
|
98
|
+
int result = stmt.executeUpdate(sql);
|
99
|
+
|
100
|
+
System.out.println("更新件数は" + result + "です。");
|
101
|
+
this.result = result;
|
102
|
+
|
103
|
+
this.resultCopcod = copcod;
|
104
|
+
this.resultEmpnum = empnum;
|
105
|
+
this.resultKnjnamsei = knjnamsei;
|
106
|
+
this.resultKnjnammei = knjnammei;
|
107
|
+
|
108
|
+
} catch (ClassNotFoundException e) {
|
109
|
+
System.out.println("JDBCドライバのロードに失敗しました。");
|
110
|
+
} catch (SQLException e) {
|
111
|
+
System.out.println("MySQLに接続できませんでした。");
|
112
|
+
System.out.println(e.getMessage());
|
113
|
+
} finally {
|
114
|
+
if (con != null) {
|
115
|
+
try {
|
116
|
+
con.close();
|
117
|
+
} catch (SQLException e) {
|
118
|
+
System.out.println("MySQLのクローズに失敗しました。");
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
33
126
|
```
|
2
使用しているDBの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
以下コードの
|
6
6
|
copcod、empnum、knjnamsei、knjnammei
|
7
7
|
の変数の中には値が入っている事、確認済です。
|
8
|
+
使用しているDBはMySQLです。
|
9
|
+
|
8
10
|
```### 発生している問題・エラーメッセージ
|
9
11
|
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 '? and empnum =? and knjnamsei =? and knjnammei =?' at line 1
|
10
12
|
|
1
Orlofsky様にご指摘いただいた部分を修正いたしました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
バインド変数を使いDBに接続する方法
|
1
|
+
バインド変数を使いDBに接続する方法 CREATE TABLE
|
body
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
### 発生している問題・エラーメッセージ
|
2
1
|
以下のエラーが発生し困っています。
|
3
2
|
色々と試してみましたが根本的な原因が何なのか分かっていないので解決策が見つかりません。
|
4
3
|
(コードの書き方がおかしいのか、DB側がおかしいのか)
|
@@ -6,11 +5,13 @@
|
|
6
5
|
以下コードの
|
7
6
|
copcod、empnum、knjnamsei、knjnammei
|
8
7
|
の変数の中には値が入っている事、確認済です。
|
9
|
-
```
|
8
|
+
```### 発生している問題・エラーメッセージ
|
10
|
-
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 '? and empnum =? and knjnamsei =? and knjnammei =?' at line 1
|
9
|
+
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 '? and empnum =? and knjnamsei =? and knjnammei =?' at line 1
|
11
10
|
|
12
11
|
SQL 構文にエラーがあります。MySQL サーバーのバージョンに対応するマニュアルをチェックして、近くで使用する正しい構文を確認してください。そしてエンプナム=?そしてクジュナムセイ=?そして、1行目で「クジュナムメイ=?」
|
12
|
+
```
|
13
13
|
|
14
|
+
|
14
15
|
```
|
15
16
|
|
16
17
|
### 該当のソースコード
|