-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTesteConexao.java
31 lines (29 loc) · 968 Bytes
/
TesteConexao.java
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
import java.sql.Connection;
import java.sql.DriverManager;
public class TesteConexao {
public static void main(String[] args) throws Exception {
//jdbc:mysql://localhost:3306/20221_fatec_ipi_poo_pessoas?useTimezone=true&serverTimezone=UTC
String host = "localhost";
String port = "3306";
String db = "20221_fatec_ipi_poo_pessoas";
String user = "root";
String password = "12345678";
String stringDeConexao = String.format(
"jdbc:mysql://%s:%s/%s?useTimezone=true&serverTimezone=UTC",
host,
port,
db
);
//cláusula catch or declare
Connection conexao = DriverManager.getConnection(
stringDeConexao,
user,
password
);
if (conexao != null)
System.out.println("Conexão OK!");
else
System.out.println("Conexão falhou!");
conexao.close();
}
}