質問編集履歴
1
ドライバ、ConnectionManagerの詳細追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,3 +27,75 @@
|
|
27
27
|
```
|
28
28
|
|
29
29
|
このような場合はどのように処理すればよいのでしょうか。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
ConnectionManagerコードは以下の通りです。
|
34
|
+
|
35
|
+
```ここに言語を入力
|
36
|
+
|
37
|
+
package login_dao;
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
import java.sql.Connection;
|
42
|
+
|
43
|
+
import java.sql.DriverManager;
|
44
|
+
|
45
|
+
import java.sql.SQLException;
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
public class ConnectionManager {
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
private static final String URL = "jdbc:mysql://localhost:3306/webdb";
|
54
|
+
|
55
|
+
private static final String USER = "○○";
|
56
|
+
|
57
|
+
private static final String PASSWORD ="○○";
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public static Connection getConnection() throws SQLException{
|
62
|
+
|
63
|
+
//データベースの接続獲得
|
64
|
+
|
65
|
+
Connection con = null;
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
try {
|
70
|
+
|
71
|
+
con = DriverManager.getConnection(URL, USER, PASSWORD);
|
72
|
+
|
73
|
+
}catch(SQLException e) {
|
74
|
+
|
75
|
+
e.printStackTrace();
|
76
|
+
|
77
|
+
throw e;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
return con;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
mysql用のドライバは
|
98
|
+
|
99
|
+
mysql-connector-java-5.1.46-bin.jar
|
100
|
+
|
101
|
+
です。
|