44 lines
909 B
Java
44 lines
909 B
Java
package bdd;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.SQLException;
|
|
|
|
import com.mysql.cj.jdbc.MysqlDataSource;
|
|
|
|
|
|
public class Liaison {
|
|
|
|
private static String username = "tp_servlet_005";
|
|
private static String password = "eGhuu1hu";
|
|
|
|
private static String serverName = "srv-bdens.insa-toulouse.fr";
|
|
private static Integer portNumber = 3306;
|
|
private static String bddNom = "tp_servlet_005";
|
|
|
|
public static Connection getConnection() {
|
|
|
|
Connection con = null;
|
|
|
|
MysqlDataSource dataSource = new MysqlDataSource();
|
|
|
|
dataSource.setServerName(serverName);
|
|
dataSource.setUser(username);
|
|
dataSource.setPassword(password);
|
|
dataSource.setDatabaseName(bddNom);
|
|
dataSource.setPortNumber(portNumber);
|
|
|
|
|
|
try {
|
|
con = dataSource.getConnection();
|
|
|
|
} catch (SQLException e) {
|
|
System.out.println("Erreur : Liaison BDD");
|
|
e.printStackTrace();
|
|
}
|
|
|
|
|
|
|
|
return con;
|
|
}
|
|
|
|
}
|