-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectarBDmySQL.java
More file actions
29 lines (23 loc) · 840 Bytes
/
ConnectarBDmySQL.java
File metadata and controls
29 lines (23 loc) · 840 Bytes
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
package dao;
import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectarBDmySQL {
private static Connection con;
public static Connection getConnection() {
try{
Class.forName("com.mysql.cj.jdbc.Driver");//com.mysql.cj.jdbc.Driver //com.mysql.jdbc.Driver
String dburl = "jdbc:mysql://localhost:3306/NameBD";
String username = "root";
String password = "root";
con = (Connection)DriverManager.getConnection( dburl, username, password);
System.out.println("Conexão estabelecida com BD \nConnection established with BD \n["+con+"]");
}catch(Exception e){
System.out.println("Erro de Conexão com BD \nDB Connection Error \n["+e.getMessage()+"]");
}
return con;
}//end getConnection
//Testing--Testando
public static void main(String[] args) {
System.out.println(getConnection());
}
}