-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
851f8e1
commit 9aaf7e8
Showing
4 changed files
with
107 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import java.sql.DriverManager; | ||
import java.sql.Connection; | ||
|
||
public class ConnectionFactory { | ||
private static String host = "localhost"; | ||
private static String port = "3306"; | ||
private static String db = "20221_fatec_ipi_poo_pessoas"; | ||
private static String user = "root"; | ||
private static String password = "1234"; | ||
private static String password = "12345678"; | ||
|
||
public static Connection getConnection() throws Exception{ | ||
public static Connection getConnection() throws Exception { | ||
return DriverManager.getConnection( | ||
String.format( | ||
"jdbc:mysql://%s:%s/%s?useTimezone=true&serverTimezone=UTC", | ||
host, | ||
port, | ||
db | ||
), | ||
user, | ||
password | ||
); | ||
String.format( | ||
"jdbc:mysql://%s:%s/%s?useTimezone=true&serverTimezone=UTC", | ||
host, | ||
port, | ||
db), | ||
user, | ||
password); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
public class TesteConexao{ | ||
|
||
public class TesteConexao { | ||
public static void main(String[] args) throws Exception { | ||
//jdbc:mysql://localhost:3306/20221_fatec_ipi_poo_pessoas?useTimezone=true&serverTimezone=UTC | ||
// 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 = "1234"; | ||
String password = "12345678"; | ||
|
||
String stringDeConexao = String.format( | ||
"jdbc:mysql://%s:%s/%s?useTimezone=true&serverTimezone=UTC", | ||
host, | ||
port, | ||
db | ||
); | ||
//cláusula catch or declare | ||
"jdbc:mysql://%s:%s/%s?useTimezone=true&serverTimezone=UTC", | ||
host, | ||
port, | ||
db); | ||
// cláusula catch or declare | ||
Connection conexao = DriverManager.getConnection( | ||
stringDeConexao, | ||
user, | ||
password | ||
); | ||
stringDeConexao, | ||
user, | ||
password); | ||
if (conexao != null) | ||
System.out.println("Conexão OK!"); | ||
else | ||
System.out.println("Conexão NOK!"); | ||
System.out.println("Conexão falhou!"); | ||
conexao.close(); | ||
} | ||
} |