-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbConnectionFactory.java
More file actions
37 lines (29 loc) · 1 KB
/
DbConnectionFactory.java
File metadata and controls
37 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.example.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DbConnectionFactory {
static {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
// 自動import
// Ctrl + Shift + O
// command + shift + O
public static Connection connect() throws SQLException {
Connection conn = null;
String user = "root";
String schemaName = ""; // ここにご自身のデータベースの名前を入力してください
// Windows版XAMPP初期設定
String url = "jdbc:mysql://localhost:3306/" + schemaName + "?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Tokyo";
String password = "";
// Mac版MAMP初期設定
// String url = "jdbc:mysql://localhost:8889/" + schemaName + "?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Tokyo";
// String password = "root";
conn = DriverManager.getConnection(url, user, password);
return conn;
}
}