Singleton DB
This commit is contained in:
parent
8791c73d38
commit
ad27139ee2
6 changed files with 28 additions and 7 deletions
BIN
Implementation/lib/mysql-connector-java-8.0.22.jar
Normal file
BIN
Implementation/lib/mysql-connector-java-8.0.22.jar
Normal file
Binary file not shown.
BIN
Implementation/mysql-connector-java-8.0.22.jar
Normal file
BIN
Implementation/mysql-connector-java-8.0.22.jar
Normal file
Binary file not shown.
Binary file not shown.
|
@ -15,6 +15,8 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import src.Model.DataBase;
|
||||
import src.Protocoles.*;
|
||||
|
||||
/**
|
||||
|
@ -197,6 +199,7 @@ public class ChatApp {
|
|||
}
|
||||
|
||||
public static void main (String[] args) throws IOException {
|
||||
DataBase Db = DataBase.getInstance();
|
||||
ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ;
|
||||
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
||||
execUDP.submit(new RunnerEcouteUDP(app));
|
||||
|
|
Binary file not shown.
|
@ -2,6 +2,7 @@ package src.Model;
|
|||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.util.Date;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class DataBase {
|
||||
private String DBurl = "jdbc:mysql://srv-bdens.insa-toulouse.fr:3306" ;
|
||||
|
@ -9,6 +10,7 @@ public class DataBase {
|
|||
private String login = "tp_servlet_006";
|
||||
private String pswd = "baePh9ei";
|
||||
|
||||
|
||||
/*Format de la table
|
||||
+--------+-------------+---------+---------------------+
|
||||
| ID | Pseudo | Actif | Date d'inscription |
|
||||
|
@ -27,19 +29,23 @@ public class DataBase {
|
|||
Message -> Msg envoye
|
||||
Date d'envoie -> Date a laquelle Source a envoye le message a destinataire
|
||||
*/
|
||||
|
||||
private static DataBase instance = null; // Singleton
|
||||
|
||||
public DataBase() {
|
||||
try {
|
||||
/*try {
|
||||
// Besoin d'installer le driver JDBC entre java IDE et le system DBMS pour faire un pont entre les deux
|
||||
Class.forName("java.sql.Driver");
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
System.out.println("Driver Installe");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Echec installation Driver");
|
||||
}
|
||||
}*/
|
||||
|
||||
try {
|
||||
// Etablir une connexion , forme : (url, "myLogin", "myPassword");
|
||||
this.connection = DriverManager.getConnection(this.DBurl,login,pswd);
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://localhost:8889/Utilisateurs?useSSL=false", "root", "Tppoo2020");
|
||||
//this.connection = DriverManager.getConnection(this.DBurl,login,pswd);
|
||||
System.out.println("Connexion Etablie");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -47,6 +53,16 @@ public class DataBase {
|
|||
}
|
||||
}
|
||||
|
||||
public static DataBase getInstance() {
|
||||
synchronized (DataBase.class) {
|
||||
DataBase DB = instance;
|
||||
if (DB == null) {
|
||||
DB = new DataBase();
|
||||
}
|
||||
return DB;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Methode permettant de creer une table pour stocker les messages entre deux utilisateurs
|
||||
* @param ID1 Id du premier utilisateur
|
||||
|
@ -136,6 +152,8 @@ public class DataBase {
|
|||
Date date = new Date();
|
||||
String dateString = date.toString();
|
||||
String BooleanActif = "true";
|
||||
String requete= "INSERT INTO Utilisateurs`(`ID`, `Pseudo`, `Actif`, `Inscription`) VALUES ('valeur 1', 'valeur 2', ...)";
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -150,10 +168,10 @@ public class DataBase {
|
|||
|
||||
|
||||
|
||||
public static void main (String[] args) throws IOException {
|
||||
DataBase DB = new DataBase();
|
||||
/*public static void main (String[] args) throws IOException {
|
||||
DataBase DB = DataBase.getInstance();
|
||||
DB.CreationTableHistorique("Auriane", "Nabil");
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue