From 92c93dc9b03063d1fbe533666fb1db96aab0a46d Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Wed, 16 Dec 2020 18:36:43 +0100 Subject: [PATCH 01/31] commit 2 : plein de tests dans createdatabase et getConnection --- src/main/java/fr/myny/database/DataBase.java | 137 ++++++++++++++++++- 1 file changed, 134 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 1a7a1ba..31550ca 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -1,11 +1,19 @@ package fr.myny.database; +import java.sql.*; +import java.util.*; +import java.io.*; +import java.util.concurrent.*; +import com.mysql.jdbc.Driver; + +import javax.sql.DataSource; + /** * La classe DataBase qui soccupera de la base de donnees */ public class DataBase { - + Connection connexion; /** @@ -23,7 +31,7 @@ public class DataBase { } /** - * La methode d'import de donnees depuis la base de donnees + * La methode dimport de donnees depuis la base de donnees */ public void importDataBase(){ @@ -32,8 +40,117 @@ public class DataBase { /** * La methode de creation de la base de donnees */ - public void createDataBase(){ + public void createDataBase(String fileName) { + /*String url = "jdbc:sqlite:C:/Users/W7/Desktop/" + fileName; + try (Connection conn = DriverManager.getConnection(url)) { + if (conn != null) { + DatabaseMetaData meta = conn.getMetaData(); + System.out.println("The driver name is " + meta.getDriverName()); + System.out.println("A new database has been created."); + } + } catch (SQLException e) { + System.out.println(e.getMessage()); + }*/ + //Class.forName("com.mysql.jdbc.Driver"); + /*try(Connection myCo = DriverManager.getConnection("jdbc:raima:rdm://C:/Users/W7/IdeaProjects/ProjetGenieLogicielLoto/src/"+fileName)){ + try(Statement mySt = myCo.createStatement()){ + mySt.execute("Create DataBase Test_DB"); + mySt.execute("Create Table Test_Table(" + + "annee_numero_de_tirage(integer)," + + "jour_de_tirage(char(10))," + + "date_de_tirage(Date)," + + "date_de_forclusion(Date)," + + "boule_1(tinyint)," + + "boule_2(tinyint)," + + "boule_3(tinyint)," + + "boule_4(tinyint)," + + "boule_5(tinyint)," + + "numero_chance(tinyint)," + + "combinaison_gagnante_en_ordre_croissant(char(20))," + + "nombre_de_gagnant_au_rang1(integer)," + + "rapport_du_rang1(integer)," + + "nombre_de_gagnant_au_rang2(integer)," + + "rapport_du_rang2(integer)," + + "nombre_de_gagnant_au_rang3(integer)," + + "rapport_du_rang3(integer)," + + "nombre_de_gagnant_au_rang4(integer)," + + "rapport_du_rang4(integer)," + + "nombre_de_gagnant_au_rang5(integer)," + + "rapport_du_rang5(integer)," + + "nombre_de_gagnant_au_rang6(integer)," + + "rapport_du_rang6(integer)," + + "numero_jokerplus(integer),"+ + "devise(char(3)),"+ + ")"); + myCo.commit(); + mySt.close(); + } + catch(Exception e){ + System.out.println(e); + } + finally { + + } + myCo.close(); + */ + /*} + catch (SQLException sqle) { + System.out.println(sqle); + }*/ + /*try { + String line; + Process p = Runtime.getRuntime().exec("C:/Users/W7/Desktop/database.sql"); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = input.readLine()) != null) { + System.out.println(line); + } + input.close(); + } + catch (Exception err) { + err.printStackTrace(); + }*/ + /*loadDatabase(); + + try { + PreparedStatement preparedStatement = connexion.prepareStatement("INSERT INTO noms(nom, prenom) VALUES(?, ?);"); + preparedStatement.setString(1, utilisateur.getNom()); + preparedStatement.setString(2, utilisateur.getPrenom()); + + preparedStatement.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + }*/ + + try { + Class.forName("com.mysql.jdbc.Driver"); + } + catch (ClassNotFoundException e) { + } + + try { + connexion = DriverManager.getConnection("jdbc:mysql://localhost:3306"); + } catch (SQLException e) { + System.out.println("oskour " +e.getStackTrace()); + } + + Statement statement = null; + ResultSet resultat = null; + try { + statement = connexion.createStatement(); + + // Exécution de la requête + resultat = statement.executeQuery("SELECT nom, prenom FROM noms;"); + + // Récupération des données + while (resultat.next()) { + String nom = resultat.getString("nom"); + String prenom = resultat.getString("prenom"); + } + } + catch (SQLException e) { + System.out.println(e); + } } @@ -43,4 +160,18 @@ public class DataBase { public void updateDataBase(){ } + public Connection getConnection() throws SQLException { + Connection conn = null; + Properties connectionProps = new Properties(); + connectionProps.put("user", "w7"); + connectionProps.put("password", "asCVhik;9$"); + if (this.dbms.equals("mysql")) { + conn = DriverManager.getConnection( + "jdbc:" + this.dbms + "://" + this.serverName + ":" + this.portNumber + "/", connectionProps); + } else if (this.dbms.equals("derby")) { + conn = DriverManager.getConnection("jdbc:" + this.dbms + ":"+this.dbName +";create=true", connectionProps); + } + System.out.println("Connected to database"); + return conn; + } } -- 2.49.1 From fe443b6f99f15a04319e052248c0c7aa62443819 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Wed, 16 Dec 2020 18:38:37 +0100 Subject: [PATCH 02/31] commit 2 : plein de tests dans createdatabase et getConnection et ca marche pas --- src/main/java/fr/myny/database/DataBase.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 31550ca..bbe6738 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -173,5 +173,6 @@ public class DataBase { } System.out.println("Connected to database"); return conn; + // } } -- 2.49.1 From 034a459e8d94e4691fdd25b6a8401601a60375e5 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Wed, 16 Dec 2020 18:50:14 +0100 Subject: [PATCH 03/31] commit 2 : plein de tests dans createdatabase et getConnection et ca marche pas --- .../java/fr/myny/database/DataBaseTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/java/fr/myny/database/DataBaseTest.java diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java new file mode 100644 index 0000000..f400d96 --- /dev/null +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -0,0 +1,28 @@ +package fr.myny.database; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class DataBaseTest { + + @Test + void fillDataBase() { + } + + @Test + void importDataBase() { + } + + @Test + void createDataBase() { + } + + @Test + void updateDataBase() { + } + + @Test + void getConnection() { + } +} \ No newline at end of file -- 2.49.1 From 02308ff3069c6bde07c0a3bfffdff082274ce57c Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Wed, 16 Dec 2020 20:58:29 +0100 Subject: [PATCH 04/31] commit 3 : Connexion (oui)+creationtable(non) --- src/main/java/fr/myny/database/DataBase.java | 232 ++++++++++-------- .../java/fr/myny/database/DataBaseTest.java | 127 +++++++++- 2 files changed, 251 insertions(+), 108 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index bbe6738..797b021 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -13,14 +13,18 @@ import javax.sql.DataSource; */ public class DataBase { - Connection connexion; - + public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; + Connection conn; + boolean test; /** * Le constructeur de DataBase */ public DataBase(){ - + try{getConnection();} + catch(SQLException sqle){ + System.out.print(sqle); + } } /** @@ -40,117 +44,117 @@ public class DataBase { /** * La methode de creation de la base de donnees */ - public void createDataBase(String fileName) { - /*String url = "jdbc:sqlite:C:/Users/W7/Desktop/" + fileName; - try (Connection conn = DriverManager.getConnection(url)) { - if (conn != null) { - DatabaseMetaData meta = conn.getMetaData(); - System.out.println("The driver name is " + meta.getDriverName()); - System.out.println("A new database has been created."); - } - + public void createDataBase() { + String sql="CREATE TABLE IF NOT EXISTS myny.Test_Table ("+ + "annee_numero_de_tirage INTEGER,"+ + "jour_de_tirage CHAR(10),"+ + "date_de_tirage DATE,"+ + "date_de_forclusion DATE,"+ + "boule_1 TINYINT,"+ + "boule_2 TINYINT,"+ + "boule_3 TINYINT,"+ + "boule_4 TINYINT,"+ + "boule_5 TINYINT,"+ + "numero_chance TINYINT,"+ + "combinaison_gagnante_en_ordre_croissantchar(20),"+ + "nombre_de_gagnant_au_rang1 INTEGER,"+ + "rapport_du_rang1 INTEGER,"+ + "nombre_de_gagnant_au_rang2 INTEGER,"+ + "rapport_du_rang2 INTEGER,"+ + "nombre_de_gagnant_au_rang3 INTEGER,"+ + "rapport_du_rang3 INTEGER,"+ + "nombre_de_gagnant_au_rang4 INTEGER,"+ + "rapport_du_rang4 INTEGER,"+ + "nombre_de_gagnant_au_rang5 INTEGER,"+ + "rapport_du_rang5 INTEGER,"+ + "nombre_de_gagnant_au_rang6 INTEGER,"+ + "rapport_du_rang6 INTEGER,"+ + "numero_jokerplus INTEGER,"+ + "deviseCHAR(10));"; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + // create a new table + test=stmt.execute(sql); } catch (SQLException e) { System.out.println(e.getMessage()); - }*/ - //Class.forName("com.mysql.jdbc.Driver"); - /*try(Connection myCo = DriverManager.getConnection("jdbc:raima:rdm://C:/Users/W7/IdeaProjects/ProjetGenieLogicielLoto/src/"+fileName)){ - try(Statement mySt = myCo.createStatement()){ - mySt.execute("Create DataBase Test_DB"); - mySt.execute("Create Table Test_Table(" + - "annee_numero_de_tirage(integer)," + - "jour_de_tirage(char(10))," + - "date_de_tirage(Date)," + - "date_de_forclusion(Date)," + - "boule_1(tinyint)," + - "boule_2(tinyint)," + - "boule_3(tinyint)," + - "boule_4(tinyint)," + - "boule_5(tinyint)," + - "numero_chance(tinyint)," + - "combinaison_gagnante_en_ordre_croissant(char(20))," + - "nombre_de_gagnant_au_rang1(integer)," + - "rapport_du_rang1(integer)," + - "nombre_de_gagnant_au_rang2(integer)," + - "rapport_du_rang2(integer)," + - "nombre_de_gagnant_au_rang3(integer)," + - "rapport_du_rang3(integer)," + - "nombre_de_gagnant_au_rang4(integer)," + - "rapport_du_rang4(integer)," + - "nombre_de_gagnant_au_rang5(integer)," + - "rapport_du_rang5(integer)," + - "nombre_de_gagnant_au_rang6(integer)," + - "rapport_du_rang6(integer)," + - "numero_jokerplus(integer),"+ - "devise(char(3)),"+ - ")"); - myCo.commit(); - mySt.close(); - } - catch(Exception e){ - System.out.println(e); - } - finally { - - } - myCo.close(); - */ - /*} - catch (SQLException sqle) { - System.out.println(sqle); - }*/ - /*try { - String line; - Process p = Runtime.getRuntime().exec("C:/Users/W7/Desktop/database.sql"); - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); - while ((line = input.readLine()) != null) { - System.out.println(line); - } - input.close(); } - catch (Exception err) { - err.printStackTrace(); + /*try(Statement mySt = conn.createStatement()){ + mySt.execute(//"CREATE SCHEMA IF NOT EXISTS Connection;"+ + "CREATE TABLE IF NOT EXISTS myny.Test_Table ("+ + "annee_numero_de_tirage INTEGER,"+ + "jour_de_tirage CHAR(10),"+ + "date_de_tirage DATE,"+ + "date_de_forclusion DATE,"+ + "boule_1 TINYINT,"+ + "boule_2 TINYINT,"+ + "boule_3 TINYINT,"+ + "boule_4 TINYINT,"+ + "boule_5 TINYINT,"+ + "numero_chance TINYINT,"+ + "combinaison_gagnante_en_ordre_croissantchar(20),"+ + "nombre_de_gagnant_au_rang1 INTEGER,"+ + "rapport_du_rang1 INTEGER,"+ + "nombre_de_gagnant_au_rang2 INTEGER,"+ + "rapport_du_rang2 INTEGER,"+ + "nombre_de_gagnant_au_rang3 INTEGER,"+ + "rapport_du_rang3 INTEGER,"+ + "nombre_de_gagnant_au_rang4 INTEGER,"+ + "rapport_du_rang4 INTEGER,"+ + "nombre_de_gagnant_au_rang5 INTEGER,"+ + "rapport_du_rang5 INTEGER,"+ + "nombre_de_gagnant_au_rang6 INTEGER,"+ + "rapport_du_rang6 INTEGER,"+ + "numero_jokerplus INTEGER,"+ + "deviseCHAR(10));"); + conn.commit(); + //mySt.close(); + //conn.close(); + } + catch(Exception e){ + System.out.println(e); + } + finally { }*/ - /*loadDatabase(); - + /* try { PreparedStatement preparedStatement = connexion.prepareStatement("INSERT INTO noms(nom, prenom) VALUES(?, ?);"); preparedStatement.setString(1, utilisateur.getNom()); preparedStatement.setString(2, utilisateur.getPrenom()); - + preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); }*/ - - try { - Class.forName("com.mysql.jdbc.Driver"); - } - catch (ClassNotFoundException e) { - } - - try { - connexion = DriverManager.getConnection("jdbc:mysql://localhost:3306"); - } catch (SQLException e) { - System.out.println("oskour " +e.getStackTrace()); - } - - Statement statement = null; - ResultSet resultat = null; - try { - statement = connexion.createStatement(); - - // Exécution de la requête - resultat = statement.executeQuery("SELECT nom, prenom FROM noms;"); - - // Récupération des données - while (resultat.next()) { - String nom = resultat.getString("nom"); - String prenom = resultat.getString("prenom"); - } - } - catch (SQLException e) { - System.out.println(e); - } + + // try { + // Class.forName("com.mysql.jdbc.Driver"); + // } + // catch (ClassNotFoundException e) { + // } + // + // try { + // conn = DriverManager.getConnection("jdbc:mysql://localhost:3306"); + // } catch (SQLException e) { + // System.out.println("oskour " +e.getStackTrace()); + // } + // + // Statement statement = null; + // ResultSet resultat = null; + // try { + // statement = conn.createStatement(); + // + // // Exécution de la requête + // resultat = statement.executeQuery("SELECT nom, prenom FROM noms;"); + // + // // Récupération des données + // while (resultat.next()) { + // String nom = resultat.getString("nom"); + // String prenom = resultat.getString("prenom"); + // } + // } + // catch (SQLException e) { + // System.out.println(e); + // } } @@ -161,17 +165,33 @@ public class DataBase { } public Connection getConnection() throws SQLException { - Connection conn = null; + /*Connection conn = null; Properties connectionProps = new Properties(); connectionProps.put("user", "w7"); - connectionProps.put("password", "asCVhik;9$"); - if (this.dbms.equals("mysql")) { + connectionProps.put("password", "asCVhik;9$");*/ + /*if (this.dbms.equals("mysql")) { conn = DriverManager.getConnection( "jdbc:" + this.dbms + "://" + this.serverName + ":" + this.portNumber + "/", connectionProps); } else if (this.dbms.equals("derby")) { conn = DriverManager.getConnection("jdbc:" + this.dbms + ":"+this.dbName +";create=true", connectionProps); + }*/ + //System.out.println("Connected to database"); + conn = null; + //Properties connectionProps = new Properties(); + //connectionProps.put("user", "mynynicolas"); + //connectionProps.put("password", "Bw0po64*"); + try { + conn = DriverManager.getConnection("jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"); + /*if (this.dbms.equals("mysql")) { + conn = DriverManager.getConnection( + "jdbc:" + this.dbms + "://" + this.serverName + ":" + this.portNumber + "/", connectionProps); + } else if (this.dbms.equals("derby")) { + conn = DriverManager.getConnection("jdbc:" + this.dbms + ":"+this.dbName +";create=true", connectionProps); + }*/ + System.out.println("Connected to database"); + }catch(SQLException e) { + System.out.println("on a des pb:" + e); } - System.out.println("Connected to database"); return conn; // } diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index f400d96..1c9452c 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -2,10 +2,18 @@ package fr.myny.database; import org.junit.jupiter.api.Test; +import java.sql.*; +import java.util.*; +import java.io.*; +import java.util.concurrent.*; +import com.mysql.jdbc.Driver; + +import javax.sql.DataSource; import static org.junit.jupiter.api.Assertions.*; -class DataBaseTest { +class DataBaseTest { + Connection connexion; @Test void fillDataBase() { } @@ -16,6 +24,116 @@ class DataBaseTest { @Test void createDataBase() { + /*String url = "jdbc:sqlite:C:/Users/W7/Desktop/" + fileName; + try (Connection conn = DriverManager.getConnection(url)) { + if (conn != null) { + DatabaseMetaData meta = conn.getMetaData(); + System.out.println("The driver name is " + meta.getDriverName()); + System.out.println("A new database has been created."); + } + + } catch (SQLException e) { + System.out.println(e.getMessage()); + }*/ + //Class.forName("com.mysql.jdbc.Driver"); + /*try(Connection myCo = DriverManager.getConnection("jdbc:raima:rdm://C:/Users/W7/IdeaProjects/ProjetGenieLogicielLoto/src/"+fileName)){ + try(Statement mySt = myCo.createStatement()){ + mySt.execute("Create DataBase Test_DB"); + mySt.execute("Create Table Test_Table(" + + "annee_numero_de_tirage(integer)," + + "jour_de_tirage(char(10))," + + "date_de_tirage(Date)," + + "date_de_forclusion(Date)," + + "boule_1(tinyint)," + + "boule_2(tinyint)," + + "boule_3(tinyint)," + + "boule_4(tinyint)," + + "boule_5(tinyint)," + + "numero_chance(tinyint)," + + "combinaison_gagnante_en_ordre_croissant(char(20))," + + "nombre_de_gagnant_au_rang1(integer)," + + "rapport_du_rang1(integer)," + + "nombre_de_gagnant_au_rang2(integer)," + + "rapport_du_rang2(integer)," + + "nombre_de_gagnant_au_rang3(integer)," + + "rapport_du_rang3(integer)," + + "nombre_de_gagnant_au_rang4(integer)," + + "rapport_du_rang4(integer)," + + "nombre_de_gagnant_au_rang5(integer)," + + "rapport_du_rang5(integer)," + + "nombre_de_gagnant_au_rang6(integer)," + + "rapport_du_rang6(integer)," + + "numero_jokerplus(integer),"+ + "devise(char(3)),"+ + ")"); + myCo.commit(); + mySt.close(); + } + catch(Exception e){ + System.out.println(e); + } + finally { + + } + myCo.close(); + */ + /*} + catch (SQLException sqle) { + System.out.println(sqle); + }*/ + /*try { + String line; + Process p = Runtime.getRuntime().exec("C:/Users/W7/Desktop/database.sql"); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = input.readLine()) != null) { + System.out.println(line); + } + input.close(); + } + catch (Exception err) { + err.printStackTrace(); + }*/ + /*loadDatabase(); + + try { + PreparedStatement preparedStatement = connexion.prepareStatement("INSERT INTO noms(nom, prenom) VALUES(?, ?);"); + preparedStatement.setString(1, utilisateur.getNom()); + preparedStatement.setString(2, utilisateur.getPrenom()); + + preparedStatement.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + }*/ + + /*try { + Class.forName("com.mysql.jdbc.Driver"); + } + catch (ClassNotFoundException e) { + } + + try { + connexion = DriverManager.getConnection("jdbc:mysql://localhost:3306"); + } catch (SQLException e) { + System.out.println("oskour " +e.getStackTrace()); + } + + Statement statement = null; + ResultSet resultat = null; + try { + statement = connexion.createStatement(); + + // Exécution de la requête + resultat = statement.executeQuery("SELECT nom, prenom FROM noms;"); + + // Récupération des données + while (resultat.next()) { + String nom = resultat.getString("nom"); + String prenom = resultat.getString("prenom"); + } + } + catch (SQLException e) { + System.out.println(e); + }*/ } @Test @@ -23,6 +141,11 @@ class DataBaseTest { } @Test - void getConnection() { + void getConnection() throws SQLException { + DataBase maDB=new DataBase(); + Connection maCo=maDB.getConnection(); + createDataBase(); + assertNotNull(maCo); + assertTrue(maDB.test); } } \ No newline at end of file -- 2.49.1 From bcb2adb7fc49408dfa871180ddb81ddb30406c81 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Fri, 18 Dec 2020 19:57:31 +0100 Subject: [PATCH 05/31] Commit 4 : Creation de la table sur phpmyadmin --- src/main/java/fr/myny/database/DataBase.java | 105 +++++++-------- .../java/fr/myny/database/DataBaseTest.java | 124 ++---------------- 2 files changed, 56 insertions(+), 173 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 797b021..6ff5c16 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -5,6 +5,7 @@ import java.util.*; import java.io.*; import java.util.concurrent.*; import com.mysql.jdbc.Driver; +import org.mariadb.jdbc.internal.com.read.dao.Results; import javax.sql.DataSource; @@ -13,18 +14,18 @@ import javax.sql.DataSource; */ public class DataBase { - public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; - Connection conn; + //public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; - boolean test; + public static String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; + Connection conn; /** * Le constructeur de DataBase */ public DataBase(){ - try{getConnection();} + /*try{getConnection();} catch(SQLException sqle){ System.out.print(sqle); - } + }*/ } /** @@ -46,36 +47,40 @@ public class DataBase { */ public void createDataBase() { String sql="CREATE TABLE IF NOT EXISTS myny.Test_Table ("+ - "annee_numero_de_tirage INTEGER,"+ - "jour_de_tirage CHAR(10),"+ - "date_de_tirage DATE,"+ - "date_de_forclusion DATE,"+ - "boule_1 TINYINT,"+ - "boule_2 TINYINT,"+ - "boule_3 TINYINT,"+ - "boule_4 TINYINT,"+ - "boule_5 TINYINT,"+ - "numero_chance TINYINT,"+ - "combinaison_gagnante_en_ordre_croissantchar(20),"+ - "nombre_de_gagnant_au_rang1 INTEGER,"+ - "rapport_du_rang1 INTEGER,"+ - "nombre_de_gagnant_au_rang2 INTEGER,"+ - "rapport_du_rang2 INTEGER,"+ - "nombre_de_gagnant_au_rang3 INTEGER,"+ - "rapport_du_rang3 INTEGER,"+ - "nombre_de_gagnant_au_rang4 INTEGER,"+ - "rapport_du_rang4 INTEGER,"+ - "nombre_de_gagnant_au_rang5 INTEGER,"+ - "rapport_du_rang5 INTEGER,"+ - "nombre_de_gagnant_au_rang6 INTEGER,"+ - "rapport_du_rang6 INTEGER,"+ - "numero_jokerplus INTEGER,"+ - "deviseCHAR(10));"; - try (Connection conn = DriverManager.getConnection(url); - Statement stmt = conn.createStatement()) { - // create a new table - test=stmt.execute(sql); + " annee_numero_de_tirage INTEGER,"+ + " jour_de_tirage VARCHAR(10),"+ + " date_de_tirage DATE,"+ + " date_de_forclusion DATE,"+ + " boule_1 TINYINT,"+ + " boule_2 TINYINT,"+ + " boule_3 TINYINT,"+ + " boule_4 TINYINT,"+ + " boule_5 TINYINT,"+ + " numero_chance TINYINT,"+ + " combinaison_gagnante_en_ordre_croissant varchar(20),"+ + " nombre_de_gagnant_au_rang1 INTEGER,"+ + " rapport_du_rang1 INTEGER,"+ + " nombre_de_gagnant_au_rang2 INTEGER,"+ + " rapport_du_rang2 INTEGER,"+ + " nombre_de_gagnant_au_rang3 INTEGER,"+ + " rapport_du_rang3 INTEGER,"+ + " nombre_de_gagnant_au_rang4 INTEGER,"+ + " rapport_du_rang4 INTEGER,"+ + " nombre_de_gagnant_au_rang5 INTEGER,"+ + " rapport_du_rang5 INTEGER,"+ + " nombre_de_gagnant_au_rang6 INTEGER,"+ + " rapport_du_rang6 INTEGER,"+ + " numero_jokerplus INTEGER,"+ + " devise VARCHAR(10));"; + //System.out.println(sql); + try { + conn = DriverManager.getConnection(url); + if(conn!=null) { + Statement stmt = conn.createStatement(); + System.out.println("statement cree"); + } } catch (SQLException e) { + System.out.println("oskour"); System.out.println(e.getMessage()); } /*try(Statement mySt = conn.createStatement()){ @@ -125,8 +130,7 @@ public class DataBase { } catch (SQLException e) { e.printStackTrace(); }*/ - - // try { + // try { // Class.forName("com.mysql.jdbc.Driver"); // } // catch (ClassNotFoundException e) { @@ -164,33 +168,16 @@ public class DataBase { public void updateDataBase(){ } - public Connection getConnection() throws SQLException { - /*Connection conn = null; - Properties connectionProps = new Properties(); - connectionProps.put("user", "w7"); - connectionProps.put("password", "asCVhik;9$");*/ - /*if (this.dbms.equals("mysql")) { - conn = DriverManager.getConnection( - "jdbc:" + this.dbms + "://" + this.serverName + ":" + this.portNumber + "/", connectionProps); - } else if (this.dbms.equals("derby")) { - conn = DriverManager.getConnection("jdbc:" + this.dbms + ":"+this.dbName +";create=true", connectionProps); - }*/ - //System.out.println("Connected to database"); + public Connection getConnection() { conn = null; - //Properties connectionProps = new Properties(); - //connectionProps.put("user", "mynynicolas"); - //connectionProps.put("password", "Bw0po64*"); try { - conn = DriverManager.getConnection("jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"); - /*if (this.dbms.equals("mysql")) { - conn = DriverManager.getConnection( - "jdbc:" + this.dbms + "://" + this.serverName + ":" + this.portNumber + "/", connectionProps); - } else if (this.dbms.equals("derby")) { - conn = DriverManager.getConnection("jdbc:" + this.dbms + ":"+this.dbName +";create=true", connectionProps); - }*/ + conn = DriverManager.getConnection(url); + //conn = DriverManager.getConnection("jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"); + //conn = DriverManager.getConnection("jdbc:mariadb://phpmyadmin.vachot.fr:3306/myny?user=mynynicolas&password=Bw0po64*"); + //conn = DriverManager.getConnection("jdbc:mariadb:../../../../../../test.db"); System.out.println("Connected to database"); }catch(SQLException e) { - System.out.println("on a des pb:" + e); + System.out.println("on a des pb:" + e.getMessage()); } return conn; // diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index 1c9452c..313a676 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -23,117 +23,15 @@ class DataBaseTest { } @Test - void createDataBase() { - /*String url = "jdbc:sqlite:C:/Users/W7/Desktop/" + fileName; - try (Connection conn = DriverManager.getConnection(url)) { - if (conn != null) { - DatabaseMetaData meta = conn.getMetaData(); - System.out.println("The driver name is " + meta.getDriverName()); - System.out.println("A new database has been created."); - } - - } catch (SQLException e) { - System.out.println(e.getMessage()); - }*/ - //Class.forName("com.mysql.jdbc.Driver"); - /*try(Connection myCo = DriverManager.getConnection("jdbc:raima:rdm://C:/Users/W7/IdeaProjects/ProjetGenieLogicielLoto/src/"+fileName)){ - try(Statement mySt = myCo.createStatement()){ - mySt.execute("Create DataBase Test_DB"); - mySt.execute("Create Table Test_Table(" + - "annee_numero_de_tirage(integer)," + - "jour_de_tirage(char(10))," + - "date_de_tirage(Date)," + - "date_de_forclusion(Date)," + - "boule_1(tinyint)," + - "boule_2(tinyint)," + - "boule_3(tinyint)," + - "boule_4(tinyint)," + - "boule_5(tinyint)," + - "numero_chance(tinyint)," + - "combinaison_gagnante_en_ordre_croissant(char(20))," + - "nombre_de_gagnant_au_rang1(integer)," + - "rapport_du_rang1(integer)," + - "nombre_de_gagnant_au_rang2(integer)," + - "rapport_du_rang2(integer)," + - "nombre_de_gagnant_au_rang3(integer)," + - "rapport_du_rang3(integer)," + - "nombre_de_gagnant_au_rang4(integer)," + - "rapport_du_rang4(integer)," + - "nombre_de_gagnant_au_rang5(integer)," + - "rapport_du_rang5(integer)," + - "nombre_de_gagnant_au_rang6(integer)," + - "rapport_du_rang6(integer)," + - "numero_jokerplus(integer),"+ - "devise(char(3)),"+ - ")"); - myCo.commit(); - mySt.close(); - } - catch(Exception e){ - System.out.println(e); - } - finally { - - } - myCo.close(); - */ - /*} - catch (SQLException sqle) { - System.out.println(sqle); - }*/ - /*try { - String line; - Process p = Runtime.getRuntime().exec("C:/Users/W7/Desktop/database.sql"); - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); - while ((line = input.readLine()) != null) { - System.out.println(line); - } - input.close(); - } - catch (Exception err) { - err.printStackTrace(); - }*/ - /*loadDatabase(); - - try { - PreparedStatement preparedStatement = connexion.prepareStatement("INSERT INTO noms(nom, prenom) VALUES(?, ?);"); - preparedStatement.setString(1, utilisateur.getNom()); - preparedStatement.setString(2, utilisateur.getPrenom()); - - preparedStatement.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - }*/ - - /*try { - Class.forName("com.mysql.jdbc.Driver"); - } - catch (ClassNotFoundException e) { - } - - try { - connexion = DriverManager.getConnection("jdbc:mysql://localhost:3306"); - } catch (SQLException e) { - System.out.println("oskour " +e.getStackTrace()); - } - - Statement statement = null; - ResultSet resultat = null; - try { - statement = connexion.createStatement(); - - // Exécution de la requête - resultat = statement.executeQuery("SELECT nom, prenom FROM noms;"); - - // Récupération des données - while (resultat.next()) { - String nom = resultat.getString("nom"); - String prenom = resultat.getString("prenom"); - } - } - catch (SQLException e) { - System.out.println(e); - }*/ + void createDataBase() throws SQLException { + DataBase maDB=new DataBase(); + maDB.createDataBase(); + Statement stmt= maDB.conn.createStatement(); + ResultSet rs=stmt.executeQuery("Select * From myny.Test_Table"); + ResultSetMetaData rsmd =rs.getMetaData(); + int nbCol=rsmd.getColumnCount(); + System.out.println("nb Col (changer la ligne juste en dessous si on modifie le nb de col): "+rsmd.getColumnCount()); + assertEquals(nbCol,25); } @Test @@ -141,11 +39,9 @@ class DataBaseTest { } @Test - void getConnection() throws SQLException { + void getConnection() { DataBase maDB=new DataBase(); Connection maCo=maDB.getConnection(); - createDataBase(); assertNotNull(maCo); - assertTrue(maDB.test); } } \ No newline at end of file -- 2.49.1 From 177283a7d94d075d55e0afc12a78fa94bd395173 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Mon, 18 Jan 2021 13:01:02 +0100 Subject: [PATCH 06/31] Remplissage de la DB avec l'excel --- src/main/java/fr/myny/database/DataBase.java | 218 +++++++++++++++--- .../java/fr/myny/database/DataBaseTest.java | 17 +- 2 files changed, 196 insertions(+), 39 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 6ff5c16..222195f 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -3,20 +3,16 @@ package fr.myny.database; import java.sql.*; import java.util.*; import java.io.*; -import java.util.concurrent.*; -import com.mysql.jdbc.Driver; -import org.mariadb.jdbc.internal.com.read.dao.Results; - -import javax.sql.DataSource; +import com.opencsv.CSVReader; /** * La classe DataBase qui soccupera de la base de donnees */ public class DataBase { - //public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; + public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; - public static String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; + //public static String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; Connection conn; /** * Le constructeur de DataBase @@ -28,11 +24,161 @@ public class DataBase { }*/ } + /** * La methode de remplissage de la base de donnees */ public void fillDataBase(){ + /*String sql="INSERT INTO 'myny.Test_Table'" + + " ('annee_numero_de_tirage', "+ + " 'jour_de_tirage', "+ + " 'date_de_tirage',"+ + " 'date_de_forclusion',"+ + " 'boule_1' ,"+ + " 'boule_2' ,"+ + " 'boule_3' ,"+ + " 'boule_4' ,"+ + " 'boule_5' ,"+ + " 'numero_chance' ,"+ + " 'combinaison_gagnante_en_ordre_croissant' ,"+ + " 'nombre_de_gagnant_au_rang1' ,"+ + " 'rapport_du_rang1' ,"+ + " 'nombre_de_gagnant_au_rang2' ,"+ + " 'rapport_du_rang2' ,"+ + " 'nombre_de_gagnant_au_rang3' ,"+ + " 'rapport_du_rang3' ,"+ + " 'nombre_de_gagnant_au_rang4' ,"+ + " 'rapport_du_rang4' ,"+ + " 'nombre_de_gagnant_au_rang5' ,"+ + " 'rapport_du_rang5' ,"+ + " 'nombre_de_gagnant_au_rang6' ,"+ + " 'rapport_du_rang6' ,"+ + " 'numero_jokerplus' ,"+ + " 'devise' ) VALUES";*/ + String sql="INSERT INTO myny.Test_Table" + + " (annee_numero_de_tirage, "+ + " jour_de_tirage, "+ + " date_de_tirage,"+ + " date_de_forclusion,"+ + " boule_1 ,"+ + " boule_2 ,"+ + " boule_3 ,"+ + " boule_4 ,"+ + " boule_5 ,"+ + " numero_chance ,"+ + " combinaison_gagnante_en_ordre_croissant ,"+ + " nombre_de_gagnant_au_rang1 ,"+ + " rapport_du_rang1 ,"+ + " nombre_de_gagnant_au_rang2 ,"+ + " rapport_du_rang2 ,"+ + " nombre_de_gagnant_au_rang3 ,"+ + " rapport_du_rang3 ,"+ + " nombre_de_gagnant_au_rang4 ,"+ + " rapport_du_rang4 ,"+ + " nombre_de_gagnant_au_rang5 ,"+ + " rapport_du_rang5 ,"+ + " nombre_de_gagnant_au_rang6 ,"+ + " rapport_du_rang6 ,"+ + " numero_jokerplus ,"+ + " devise ) VALUES \n"; + try { + Scanner sc = new Scanner(new File("c:/Users/cocof/Bureau/nouveau_loto.csv")); + sc.useDelimiter(";|\\n"); //sets the delimiter pattern + int i=0,j; + String line=sc.nextLine(); + line=""; + String date, jour, mois, an; + while (sc.hasNext()) //returns a boolean value + { + j=(i%25)+1; + if(j==1) { + line=line+'('; + line=line+sc.next().replace(",","."); + line=line+';'; + } + if(j<25 && j>1) { + if (j==2 ||j==11){ + line=line+"\'"+sc.next().replace(",",".")+"\',"; + } + else if (j==3 ||j==4){ + date=sc.next().replace(",","."); + jour=date.substring(0,2); + mois=date.substring(3,5); + an=date.substring(6,10); + line=line+"\'"+an+"-"+mois+"-"+jour+"\',"; + } + else{ + line=line+sc.next().replace(",","."); + line=line+';'; + } + } + if(j==25) { + line=line+"\'"+sc.next().replace(",",".")+"\'"; + line=line+')'; + line=line.replaceAll("\\s",""); + line = line.replaceAll(";", ","); + if(sc.hasNext()) { + line = line+ ","; + } + else{ + line = line+ ";"; + } + //System.out.println(line); + sql=sql+line; + line=""; + } + i++; + //System.out.println(sc.nextLine()); + //System.out.print(sc.next()); //find and returns the next complete token from this scanner + } + System.out.println(sql); + //System.out.println(sql); + /*CSVReader reader = new CSVReader(new FileReader("c:/Users/cocof/Bureau/nouveau_loto.csv")); + String[] nextLine=reader.readNext(); + while ((nextLine = reader.readNext()) != null) { + // nextLine[] is an array of values from the line + for (int j = 0; j < nextLine.length - 1; j++) { + if (j==0){ + sql=sql+"("; + } + sql=sql+nextLine[j]; + if (j==nextLine.length-1){ + sql=sql+"),"; + } + else{ + sql=sql+","; + } + //System.out.println(nextLine[j]); + } + sql=sql+";"; + } + System.out.println(sql); + + conn = DriverManager.getConnection(url); + if(conn!=null) { + Statement stmt = conn.createStatement(); + stmt.executeQuery(sql); + conn.commit(); + System.out.println("statement cree"); + }*/ + } + catch (Exception e){ + System.out.println(e.getMessage()); + } + try { + conn = DriverManager.getConnection(url); + if(conn!=null) { + Statement stmt = conn.createStatement(); + stmt.executeQuery(sql); + conn.commit(); + //conn.close(); + System.out.println("statement cree"); + } + } catch (SQLException e) { + System.out.println("oskour"); + System.out.println(e.getMessage()); + } } /** @@ -47,36 +193,39 @@ public class DataBase { */ public void createDataBase() { String sql="CREATE TABLE IF NOT EXISTS myny.Test_Table ("+ - " annee_numero_de_tirage INTEGER,"+ - " jour_de_tirage VARCHAR(10),"+ - " date_de_tirage DATE,"+ - " date_de_forclusion DATE,"+ - " boule_1 TINYINT,"+ - " boule_2 TINYINT,"+ - " boule_3 TINYINT,"+ - " boule_4 TINYINT,"+ - " boule_5 TINYINT,"+ - " numero_chance TINYINT,"+ - " combinaison_gagnante_en_ordre_croissant varchar(20),"+ - " nombre_de_gagnant_au_rang1 INTEGER,"+ - " rapport_du_rang1 INTEGER,"+ - " nombre_de_gagnant_au_rang2 INTEGER,"+ - " rapport_du_rang2 INTEGER,"+ - " nombre_de_gagnant_au_rang3 INTEGER,"+ - " rapport_du_rang3 INTEGER,"+ - " nombre_de_gagnant_au_rang4 INTEGER,"+ - " rapport_du_rang4 INTEGER,"+ - " nombre_de_gagnant_au_rang5 INTEGER,"+ - " rapport_du_rang5 INTEGER,"+ - " nombre_de_gagnant_au_rang6 INTEGER,"+ - " rapport_du_rang6 INTEGER,"+ - " numero_jokerplus INTEGER,"+ - " devise VARCHAR(10));"; + " annee_numero_de_tirage INTEGER,"+ //1 + " jour_de_tirage VARCHAR(10),"+ //2 VARCHAR + " date_de_tirage DATE,"+ //3 DATE + " date_de_forclusion DATE,"+ //4 DATE + " boule_1 TINYINT,"+ //5 + " boule_2 TINYINT,"+ //6 + " boule_3 TINYINT,"+ //7 + " boule_4 TINYINT,"+ //8 + " boule_5 TINYINT,"+ //9 + " numero_chance TINYINT,"+ //10 + " combinaison_gagnante_en_ordre_croissant varchar(20),"+//11 VARCHAR + " nombre_de_gagnant_au_rang1 INTEGER,"+ //12 + " rapport_du_rang1 INTEGER,"+ //13 + " nombre_de_gagnant_au_rang2 INTEGER,"+ //14 + " rapport_du_rang2 INTEGER,"+ //15 + " nombre_de_gagnant_au_rang3 INTEGER,"+ //16 + " rapport_du_rang3 INTEGER,"+ //17 + " nombre_de_gagnant_au_rang4 INTEGER,"+ //18 + " rapport_du_rang4 INTEGER,"+ //19 + " nombre_de_gagnant_au_rang5 INTEGER,"+ //20 + " rapport_du_rang5 INTEGER,"+ //21 + " nombre_de_gagnant_au_rang6 INTEGER,"+ //22 + " rapport_du_rang6 INTEGER,"+ //23 + " numero_jokerplus INTEGER,"+ //24 + " devise VARCHAR(10));"; //25 VARCHAR //System.out.println(sql); try { conn = DriverManager.getConnection(url); if(conn!=null) { Statement stmt = conn.createStatement(); + stmt.executeQuery(sql); + conn.commit(); + //conn.close(); System.out.println("statement cree"); } } catch (SQLException e) { @@ -175,7 +324,10 @@ public class DataBase { //conn = DriverManager.getConnection("jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"); //conn = DriverManager.getConnection("jdbc:mariadb://phpmyadmin.vachot.fr:3306/myny?user=mynynicolas&password=Bw0po64*"); //conn = DriverManager.getConnection("jdbc:mariadb:../../../../../../test.db"); - System.out.println("Connected to database"); + if(conn!=null) { + System.out.println("Connected to database"); + System.out.println(conn); + } }catch(SQLException e) { System.out.println("on a des pb:" + e.getMessage()); } diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index 313a676..0ff7e25 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -5,17 +5,22 @@ import org.junit.jupiter.api.Test; import java.sql.*; import java.util.*; import java.io.*; -import java.util.concurrent.*; -import com.mysql.jdbc.Driver; - -import javax.sql.DataSource; import static org.junit.jupiter.api.Assertions.*; - +import fr.myny.database.*; class DataBaseTest { Connection connexion; @Test - void fillDataBase() { + void fillDataBase() throws SQLException { + + DataBase maDB=new DataBase(); + Connection maCo=maDB.getConnection(); + assertNotNull(maCo); + //maDB.fillDataBase(); + Statement stmt= maDB.conn.createStatement(); + ResultSet rs=stmt.executeQuery("SELECT Count(*) As total From myny.Test_Table Where 1=1"); + System.out.println("nb lignes (changer la ligne juste en dessous si on modifie le nb de col): "+rs.getInt("total")); + assertEquals(1317,rs); } @Test -- 2.49.1 From 2967031a600e6961da011e24eba12034303acaa4 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Mon, 18 Jan 2021 13:23:50 +0100 Subject: [PATCH 07/31] Remplissage de la DB avec l'excel --- src/test/java/fr/myny/database/DataBaseTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index 0ff7e25..498dc43 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -18,9 +18,12 @@ class DataBaseTest { assertNotNull(maCo); //maDB.fillDataBase(); Statement stmt= maDB.conn.createStatement(); - ResultSet rs=stmt.executeQuery("SELECT Count(*) As total From myny.Test_Table Where 1=1"); - System.out.println("nb lignes (changer la ligne juste en dessous si on modifie le nb de col): "+rs.getInt("total")); - assertEquals(1317,rs); + ResultSet rs=stmt.executeQuery("SELECT Count(*) From myny.Test_Table"); + rs.next(); + long nbcolret= rs.getLong(1); + //System.out.println("nb lignes (changer la ligne juste en dessous si on modifie le nb de lignes): "+rs.getInt("total")); + System.out.println("nb lignes (changer la ligne juste en dessous si on modifie le nb de lignes): "+rs.getLong(1)); + assertEquals(1317,rs.getLong(1)); } @Test -- 2.49.1 From e83f91adb81790b55ba10676289b8becd014e36b Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Mon, 18 Jan 2021 17:04:42 +0100 Subject: [PATCH 08/31] mise a jour de la db, test avant de le faire --- src/main/java/fr/myny/database/DataBase.java | 128 ++++++++++++++++-- .../java/fr/myny/database/DataBaseTest.java | 6 +- 2 files changed, 122 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 222195f..aad1c37 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -10,18 +10,14 @@ import com.opencsv.CSVReader; */ public class DataBase { - public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; + //public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; - //public static String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; + public static String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; Connection conn; /** * Le constructeur de DataBase */ public DataBase(){ - /*try{getConnection();} - catch(SQLException sqle){ - System.out.print(sqle); - }*/ } @@ -88,8 +84,7 @@ public class DataBase { String line=sc.nextLine(); line=""; String date, jour, mois, an; - while (sc.hasNext()) //returns a boolean value - { + while (sc.hasNext()){ j=(i%25)+1; if(j==1) { line=line+'('; @@ -167,7 +162,7 @@ public class DataBase { System.out.println(e.getMessage()); } try { - conn = DriverManager.getConnection(url); + conn = this.getConnection(); if(conn!=null) { Statement stmt = conn.createStatement(); stmt.executeQuery(sql); @@ -314,9 +309,121 @@ public class DataBase { /** * La methode de mise a jour de la base de donnees */ - public void updateDataBase(){ + public void updateDataBase() throws FileNotFoundException { + /* String sql="INSERT INTO myny.Test_Table" + + " (annee_numero_de_tirage, "+ + " jour_de_tirage, "+ + " date_de_tirage,"+ + " date_de_forclusion,"+ + " boule_1 ,"+ + " boule_2 ,"+ + " boule_3 ,"+ + " boule_4 ,"+ + " boule_5 ,"+ + " numero_chance ,"+ + " combinaison_gagnante_en_ordre_croissant ,"+ + " nombre_de_gagnant_au_rang1 ,"+ + " rapport_du_rang1 ,"+ + " nombre_de_gagnant_au_rang2 ,"+ + " rapport_du_rang2 ,"+ + " nombre_de_gagnant_au_rang3 ,"+ + " rapport_du_rang3 ,"+ + " nombre_de_gagnant_au_rang4 ,"+ + " rapport_du_rang4 ,"+ + " nombre_de_gagnant_au_rang5 ,"+ + " rapport_du_rang5 ,"+ + " nombre_de_gagnant_au_rang6 ,"+ + " rapport_du_rang6 ,"+ + " numero_jokerplus ,"+ + " devise ) VALUES \n"; + + + try { + Scanner sc = new Scanner(new File("c:/Users/cocof/Bureau/nouveau_loto.csv")); + sc.useDelimiter(";|\\n"); //sets the delimiter pattern + int i=0,j; + String line=sc.nextLine(); + line=""; + String date, jour, mois, an; + String annee_numero_de_tirage=sc.next(); + while (sc.hasNext()&&annee_numero_de_tirage!=){ + j=(i%25)+1; + if(j==1) { + line=line+'('; + line=line+sc.next().replace(",","."); + line=line+';'; + } + if(j<25 && j>1) { + if (j==2 ||j==11){ + line=line+"\'"+sc.next().replace(",",".")+"\',"; + } + else if (j==3 ||j==4){ + date=sc.next().replace(",","."); + jour=date.substring(0,2); + mois=date.substring(3,5); + an=date.substring(6,10); + line=line+"\'"+an+"-"+mois+"-"+jour+"\',"; + } + else{ + line=line+sc.next().replace(",","."); + line=line+';'; + } + } + if(j==25) { + line=line+"\'"+sc.next().replace(",",".")+"\'"; + line=line+')'; + line=line.replaceAll("\\s",""); + line = line.replaceAll(";", ","); + if(sc.hasNext()) { + line = line+ ","; + } + else{ + line = line+ ";"; + } + //System.out.println(line); + sql=sql+line; + line=""; + } + i++; + //System.out.println(sc.nextLine()); + //System.out.print(sc.next()); //find and returns the next complete token from this scanner + } + } + catch (Exception e){ + System.out.println(e.getMessage()); + } + */ + try { + conn = this.getConnection(); + if(conn!=null) { + Scanner sc = new Scanner(new File("c:/Users/cocof/Bureau/nouveau_loto.csv")); + sc.useDelimiter(";|\\n"); //sets the delimiter pattern + String line=sc.nextLine(); + line=""; + long annee_numero_de_tirage=Long.parseLong(sc.next()); + //sc.nextLine(); + //annee_numero_de_tirage=Long.parseLong(sc.next()); + System.out.println("numero en haut du fichier csv :"+annee_numero_de_tirage); + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT MAX(annee_numero_de_tirage) FROM myny.Test_Table;"); + rs.next(); + //conn.close(); + System.out.println("numero max de la db :"+rs.getLong(1)); + } + } catch (SQLException e) { + System.out.println("oskour update"); + System.out.println(e.getMessage()); + } } + + + + + + /** + * La methode de connection + */ public Connection getConnection() { conn = null; try { @@ -332,6 +439,5 @@ public class DataBase { System.out.println("on a des pb:" + e.getMessage()); } return conn; - // } } diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index 498dc43..8cff51f 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -43,7 +43,11 @@ class DataBaseTest { } @Test - void updateDataBase() { + void updateDataBase() throws FileNotFoundException { + DataBase maDB=new DataBase(); + Connection maCo=maDB.getConnection(); + maDB.updateDataBase(); + assertNotNull(maCo); } @Test -- 2.49.1 From e02bc79c0a31b648a85ad53bd8d1f928f6a67b20 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Mon, 18 Jan 2021 17:45:49 +0100 Subject: [PATCH 09/31] Remplissage de la DB avec l'excel, verification requete --- src/main/java/fr/myny/database/DataBase.java | 68 ++++++++++++++++---- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index aad1c37..5e701a4 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -4,14 +4,13 @@ import java.sql.*; import java.util.*; import java.io.*; -import com.opencsv.CSVReader; /** * La classe DataBase qui soccupera de la base de donnees */ public class DataBase { //public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; - + public static final int NBCOL =25; public static String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; Connection conn; /** @@ -85,13 +84,13 @@ public class DataBase { line=""; String date, jour, mois, an; while (sc.hasNext()){ - j=(i%25)+1; + j=(i% NBCOL)+1; if(j==1) { line=line+'('; line=line+sc.next().replace(",","."); line=line+';'; } - if(j<25 && j>1) { + if(j< NBCOL && j>1) { if (j==2 ||j==11){ line=line+"\'"+sc.next().replace(",",".")+"\',"; } @@ -107,7 +106,7 @@ public class DataBase { line=line+';'; } } - if(j==25) { + if(j== NBCOL) { line=line+"\'"+sc.next().replace(",",".")+"\'"; line=line+')'; line=line.replaceAll("\\s",""); @@ -310,7 +309,7 @@ public class DataBase { * La methode de mise a jour de la base de donnees */ public void updateDataBase() throws FileNotFoundException { - /* String sql="INSERT INTO myny.Test_Table" + + String sql="INSERT INTO myny.Test_Table" + " (annee_numero_de_tirage, "+ " jour_de_tirage, "+ " date_de_tirage,"+ @@ -339,7 +338,7 @@ public class DataBase { - try { + /* try { Scanner sc = new Scanner(new File("c:/Users/cocof/Bureau/nouveau_loto.csv")); sc.useDelimiter(";|\\n"); //sets the delimiter pattern int i=0,j; @@ -348,13 +347,13 @@ public class DataBase { String date, jour, mois, an; String annee_numero_de_tirage=sc.next(); while (sc.hasNext()&&annee_numero_de_tirage!=){ - j=(i%25)+1; + j=(i%NBCOL)+1; if(j==1) { line=line+'('; line=line+sc.next().replace(",","."); line=line+';'; } - if(j<25 && j>1) { + if(j1) { if (j==2 ||j==11){ line=line+"\'"+sc.next().replace(",",".")+"\',"; } @@ -370,7 +369,7 @@ public class DataBase { line=line+';'; } } - if(j==25) { + if(j==NBCOL) { line=line+"\'"+sc.next().replace(",",".")+"\'"; line=line+')'; line=line.replaceAll("\\s",""); @@ -401,15 +400,60 @@ public class DataBase { sc.useDelimiter(";|\\n"); //sets the delimiter pattern String line=sc.nextLine(); line=""; - long annee_numero_de_tirage=Long.parseLong(sc.next()); + int i=0,j=0; + String date, jour, mois, an; + long anEntre=Long.parseLong(sc.next()); //sc.nextLine(); //annee_numero_de_tirage=Long.parseLong(sc.next()); - System.out.println("numero en haut du fichier csv :"+annee_numero_de_tirage); + System.out.println("numero en haut du fichier csv :"+anEntre); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT MAX(annee_numero_de_tirage) FROM myny.Test_Table;"); rs.next(); + long maxvaldb=rs.getLong(1); //conn.close(); System.out.println("numero max de la db :"+rs.getLong(1)); + while(anEntre>maxvaldb) { + for (i = 0; i < NBCOL; i++) { + System.out.println("i: "+i+", j :"+j); + j = (i % NBCOL) + 1; + if (j == 1) { + line = line + '('; + line = line + anEntre; + line = line + ';'; + //sc.next(); + } + if (j < NBCOL && j > 1) { + if (j == 2 || j == 11) { + line = line + "\'" + sc.next().replace(",", ".") + "\',"; + } else if (j == 3 || j == 4) { + date = sc.next().replace(",", "."); + jour = date.substring(0, 2); + mois = date.substring(3, 5); + an = date.substring(6, 10); + line = line + "\'" + an + "-" + mois + "-" + jour + "\',"; + } else { + line = line + sc.next().replace(",", "."); + line = line + ';'; + } + } + if (j == NBCOL) { + line = line + "\'" + sc.next().replace(",", ".") + "\'"; + line = line + ')'; + line = line.replaceAll("\\s", ""); + line = line.replaceAll(";", ","); + anEntre = Long.parseLong(sc.next()); + if (anEntre > maxvaldb) { + line = line + ","; + } else { + line = line + ";"; + } + //System.out.println(line); + sql = sql + line; + line = ""; + } + } + } + System.out.println(sql); } } catch (SQLException e) { System.out.println("oskour update"); -- 2.49.1 From 6a45cf5cb09ec106cde37b459f97f063dedca12e Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Tue, 19 Jan 2021 01:05:01 +0100 Subject: [PATCH 10/31] methode updatedatabase entierement commentee et documentee --- src/main/java/fr/myny/database/DataBase.java | 152 +++++++----------- .../java/fr/myny/database/DataBaseTest.java | 4 +- 2 files changed, 64 insertions(+), 92 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 5e701a4..1f8cde2 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -11,7 +11,8 @@ import java.io.*; public class DataBase { //public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; public static final int NBCOL =25; - public static String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; + public static final String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; + public static final String filePath="c:/Users/cocof/Bureau/nouveau_loto.csv"; Connection conn; /** * Le constructeur de DataBase @@ -77,7 +78,7 @@ public class DataBase { " numero_jokerplus ,"+ " devise ) VALUES \n"; try { - Scanner sc = new Scanner(new File("c:/Users/cocof/Bureau/nouveau_loto.csv")); + Scanner sc = new Scanner(new File(filePath)); sc.useDelimiter(";|\\n"); //sets the delimiter pattern int i=0,j; String line=sc.nextLine(); @@ -128,7 +129,7 @@ public class DataBase { System.out.println(sql); //System.out.println(sql); - /*CSVReader reader = new CSVReader(new FileReader("c:/Users/cocof/Bureau/nouveau_loto.csv")); + /*CSVReader reader = new CSVReader(new FileReader(filePath)); String[] nextLine=reader.readNext(); while ((nextLine = reader.readNext()) != null) { // nextLine[] is an array of values from the line @@ -307,9 +308,20 @@ public class DataBase { /** * La methode de mise a jour de la base de donnees + * @return sql String, contenant la requete SQL + * @var sc Scanner, l objet qui servira a lire le fichier csv + * @var line String, ligne contenant l'ajout a effectuer + * @var i int, un compteur de valeurs lues, + * @var j int, qui suit i%NBCOL + * @var nbValAj int qui augmente si on doit ajouter des lignes + * @var date String, la valeur de la date lue + * @var jour String, le jour lu + * @var mois String, le mois lu + * @var an String, l annee lue + * @var anEntre long, valeur lue pour l annee et le numero de tirage. sert a definir si la valeur est a ajouter dans la table */ - public void updateDataBase() throws FileNotFoundException { - String sql="INSERT INTO myny.Test_Table" + + public String updateDataBase() throws FileNotFoundException { + String sql="INSERT INTO myny.Test_Table" + //le debut de la requete, specifiant laction a effectuer, la table et la db " (annee_numero_de_tirage, "+ " jour_de_tirage, "+ " date_de_tirage,"+ @@ -335,130 +347,88 @@ public class DataBase { " rapport_du_rang6 ,"+ " numero_jokerplus ,"+ " devise ) VALUES \n"; - - - - /* try { - Scanner sc = new Scanner(new File("c:/Users/cocof/Bureau/nouveau_loto.csv")); - sc.useDelimiter(";|\\n"); //sets the delimiter pattern - int i=0,j; - String line=sc.nextLine(); - line=""; - String date, jour, mois, an; - String annee_numero_de_tirage=sc.next(); - while (sc.hasNext()&&annee_numero_de_tirage!=){ - j=(i%NBCOL)+1; - if(j==1) { - line=line+'('; - line=line+sc.next().replace(",","."); - line=line+';'; - } - if(j1) { - if (j==2 ||j==11){ - line=line+"\'"+sc.next().replace(",",".")+"\',"; - } - else if (j==3 ||j==4){ - date=sc.next().replace(",","."); - jour=date.substring(0,2); - mois=date.substring(3,5); - an=date.substring(6,10); - line=line+"\'"+an+"-"+mois+"-"+jour+"\',"; - } - else{ - line=line+sc.next().replace(",","."); - line=line+';'; - } - } - if(j==NBCOL) { - line=line+"\'"+sc.next().replace(",",".")+"\'"; - line=line+')'; - line=line.replaceAll("\\s",""); - line = line.replaceAll(";", ","); - if(sc.hasNext()) { - line = line+ ","; - } - else{ - line = line+ ";"; - } - //System.out.println(line); - sql=sql+line; - line=""; - } - i++; - //System.out.println(sc.nextLine()); - //System.out.print(sc.next()); //find and returns the next complete token from this scanner - } - } - catch (Exception e){ - System.out.println(e.getMessage()); - } - */ try { - conn = this.getConnection(); - if(conn!=null) { - Scanner sc = new Scanner(new File("c:/Users/cocof/Bureau/nouveau_loto.csv")); - sc.useDelimiter(";|\\n"); //sets the delimiter pattern - String line=sc.nextLine(); - line=""; - int i=0,j=0; + conn = this.getConnection(); //initialisation de la connexion + if(conn!=null) { //si la co est bonne + Scanner sc = new Scanner(new File(filePath)); //lire le fichier donne + sc.useDelimiter(";|\\n"); //les delimiteurs seront ; et \n + sc.nextLine(); //on ne conserve pas la premiere ligne, contenant les metadonnees + int i=0,j=0, nbValAj=0; String date, jour, mois, an; - long anEntre=Long.parseLong(sc.next()); - //sc.nextLine(); - //annee_numero_de_tirage=Long.parseLong(sc.next()); - System.out.println("numero en haut du fichier csv :"+anEntre); - Statement stmt = conn.createStatement(); + String line=""; + long anEntre=Long.parseLong(sc.next()); //lecture de l id en haut du tableau(donc le plus grand, cest ce qu on a constate en lisant le csv + //System.out.println("numero en haut du fichier csv :"+anEntre); + Statement stmt = conn.createStatement(); //recuperation du nb de lignes dans la table ResultSet rs = stmt.executeQuery("SELECT MAX(annee_numero_de_tirage) FROM myny.Test_Table;"); rs.next(); long maxvaldb=rs.getLong(1); - //conn.close(); - System.out.println("numero max de la db :"+rs.getLong(1)); + //System.out.println("numero max de la db :"+rs.getLong(1)); + /*comme les nombres de la premiere col sont decroissants, le nb le plus grand est lu en premier, + on va donc lire les nombres jusqua arriver a la plus haute valeur entree dans la table. On ne + pourrait probablement pas utiliser cette methode pour remplir la table en entier*/ while(anEntre>maxvaldb) { - for (i = 0; i < NBCOL; i++) { - System.out.println("i: "+i+", j :"+j); + nbValAj++;//des quon rentre dans la boucle, on sait qu'on va devoir mettre a jour la table car cette valeur est>0 + for (i = 0; i < NBCOL; i++) {//on remplit la ligne en effectuant une lecture par col j = (i % NBCOL) + 1; if (j == 1) { - line = line + '('; + line = line + '(';//debut de la ligne a jouter line = line + anEntre; - line = line + ';'; + line = line + ';';//on met un point virgule mais on le remplacera plus tard //sc.next(); } - if (j < NBCOL && j > 1) { + if (j < NBCOL && j > 1) {//pour chaque colonne, on va faire en sorte de mettre le champ dans la onne mise en fore pour qu'il soit accepté par la db if (j == 2 || j == 11) { line = line + "\'" + sc.next().replace(",", ".") + "\',"; - } else if (j == 3 || j == 4) { + } else if (j == 3 || j == 4) {//pour les col 3 et 4, il s'agit d'une date, on va donc passer dela forme jj-mm-aaaa a la forme aaaa-mm-jj date = sc.next().replace(",", "."); jour = date.substring(0, 2); mois = date.substring(3, 5); an = date.substring(6, 10); line = line + "\'" + an + "-" + mois + "-" + jour + "\',"; - } else { + } else {//pour les autres col, on va simplement les remplir line = line + sc.next().replace(",", "."); line = line + ';'; } } - if (j == NBCOL) { + if (j == NBCOL) {//pour la derniere col line = line + "\'" + sc.next().replace(",", ".") + "\'"; - line = line + ')'; - line = line.replaceAll("\\s", ""); + line = line + ')';//on la remplit + line = line.replaceAll("\\s", "");//on remplace les caracteres qui nous derangent line = line.replaceAll(";", ","); - anEntre = Long.parseLong(sc.next()); - if (anEntre > maxvaldb) { + anEntre = Long.parseLong(sc.next());//on lit le prochain id de l'entree + if (anEntre > maxvaldb) {//on defini si on doit encore ajouter des lignes a la requete line = line + ","; - } else { + } else {//ou si on doit cloturer la requete line = line + ";"; } //System.out.println(line); - sql = sql + line; + sql = sql + line + "\n";//on ajoute la ligne a la requete line = ""; } } } System.out.println(sql); + if (nbValAj>0) {//on effectue la requete si on a des maj a faire + try { + conn = this.getConnection(); + if (conn != null) { + stmt = conn.createStatement(); + stmt.executeQuery(sql); + conn.commit(); + //conn.close(); + System.out.println("update validee"); + } + } catch (SQLException e) { + System.out.println("oskour into update"); + System.out.println(e.getMessage()); + } + } } } catch (SQLException e) { System.out.println("oskour update"); System.out.println(e.getMessage()); } + return sql; } diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index 8cff51f..541e6c7 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -46,8 +46,10 @@ class DataBaseTest { void updateDataBase() throws FileNotFoundException { DataBase maDB=new DataBase(); Connection maCo=maDB.getConnection(); - maDB.updateDataBase(); + String requete = maDB.updateDataBase(); + System.out.println(requete); assertNotNull(maCo); + } @Test -- 2.49.1 From 3113313907d7a7f26914bdfc5793d23dbcb85c62 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Tue, 19 Jan 2021 18:08:23 +0100 Subject: [PATCH 11/31] =?UTF-8?q?Remplissage=20de=20la=20DB=20avec=20l'exc?= =?UTF-8?q?el,=20verification=20requete,=20mise=20=C3=A0=20jour...=20tout?= =?UTF-8?q?=20plein=20de=20commentaires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 + .idea/compiler.xml | 16 + .idea/dbnavigator.xml | 552 ++++++++++++++++++ .idea/encodings.xml | 6 + .idea/jarRepositories.xml | 20 + ..._org_apiguardian_apiguardian_api_1_1_0.xml | 13 + ..._junit_jupiter_junit_jupiter_api_5_7_0.xml | 13 + ...nit_jupiter_junit_jupiter_engine_5_7_0.xml | 13 + ..._platform_junit_platform_commons_1_7_0.xml | 13 + ...t_platform_junit_platform_engine_1_7_0.xml | 13 + ...Maven__org_opentest4j_opentest4j_1_2_0.xml | 13 + .../Maven__org_slf4j_slf4j_api_1_7_25.xml | 13 + .../Maven__org_slf4j_slf4j_simple_1_7_25.xml | 13 + .idea/libraries/commons_lang3_3_11.xml | 9 + .idea/libraries/mariadb_java_client_2_7_1.xml | 9 + .../libraries/mysql_connector_java_8_0_22.xml | 9 + .idea/libraries/opencsv_5_3.xml | 9 + .idea/misc.xml | 11 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + ProjetGenieLogicielLoto.iml | 8 +- src/main/java/test.java | 13 +- 22 files changed, 779 insertions(+), 4 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/dbnavigator.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_0.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_7_0.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_7_0.xml create mode 100644 .idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_7_0.xml create mode 100644 .idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_7_0.xml create mode 100644 .idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml create mode 100644 .idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml create mode 100644 .idea/libraries/Maven__org_slf4j_slf4j_simple_1_7_25.xml create mode 100644 .idea/libraries/commons_lang3_3_11.xml create mode 100644 .idea/libraries/mariadb_java_client_2_7_1.xml create mode 100644 .idea/libraries/mysql_connector_java_8_0_22.xml create mode 100644 .idea/libraries/opencsv_5_3.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b9417ab --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..20d6cbe --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,552 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
\ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63e9001 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_0.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_0.xml new file mode 100644 index 0000000..f854ab0 --- /dev/null +++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_7_0.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_7_0.xml new file mode 100644 index 0000000..cc01e3f --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_7_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_7_0.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_7_0.xml new file mode 100644 index 0000000..f198e4b --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_7_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_7_0.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_7_0.xml new file mode 100644 index 0000000..cde8a48 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_7_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_7_0.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_7_0.xml new file mode 100644 index 0000000..3391deb --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_7_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml new file mode 100644 index 0000000..fbc1b16 --- /dev/null +++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml new file mode 100644 index 0000000..20e8163 --- /dev/null +++ b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_slf4j_simple_1_7_25.xml b/.idea/libraries/Maven__org_slf4j_slf4j_simple_1_7_25.xml new file mode 100644 index 0000000..8bc862b --- /dev/null +++ b/.idea/libraries/Maven__org_slf4j_slf4j_simple_1_7_25.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/commons_lang3_3_11.xml b/.idea/libraries/commons_lang3_3_11.xml new file mode 100644 index 0000000..9b31456 --- /dev/null +++ b/.idea/libraries/commons_lang3_3_11.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mariadb_java_client_2_7_1.xml b/.idea/libraries/mariadb_java_client_2_7_1.xml new file mode 100644 index 0000000..5309251 --- /dev/null +++ b/.idea/libraries/mariadb_java_client_2_7_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_java_8_0_22.xml b/.idea/libraries/mysql_connector_java_8_0_22.xml new file mode 100644 index 0000000..459146b --- /dev/null +++ b/.idea/libraries/mysql_connector_java_8_0_22.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/opencsv_5_3.xml b/.idea/libraries/opencsv_5_3.xml new file mode 100644 index 0000000..64467cd --- /dev/null +++ b/.idea/libraries/opencsv_5_3.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7193838 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..19b7cd7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProjetGenieLogicielLoto.iml b/ProjetGenieLogicielLoto.iml index 25b7aca..be894ed 100644 --- a/ProjetGenieLogicielLoto.iml +++ b/ProjetGenieLogicielLoto.iml @@ -5,20 +5,22 @@ - - - + + + + + \ No newline at end of file diff --git a/src/main/java/test.java b/src/main/java/test.java index 604d790..342e12f 100644 --- a/src/main/java/test.java +++ b/src/main/java/test.java @@ -1,5 +1,16 @@ +import com.opencsv.CSVReader; +import com.opencsv.exceptions.CsvException; +import fr.myny.database.DataBase; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.sql.*; +import java.util.*; +import java.io.*; +import com.opencsv.CSVReader; + public class test{ - public static void main(String[] args){ + public static void main(String[] args) { System.out.println("Il n'y a rien a voir !"); System.out.println("nico fait un test"); System.out.println("Il Je test les branchs"); -- 2.49.1 From bd7fe76f6bbda3ac0143822201aa716e08cf7478 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Tue, 19 Jan 2021 18:08:46 +0100 Subject: [PATCH 12/31] =?UTF-8?q?Remplissage=20de=20la=20DB=20avec=20l'exc?= =?UTF-8?q?el,=20verification=20requete,=20mise=20=C3=A0=20jour...=20tout?= =?UTF-8?q?=20plein=20de=20commentaires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/myny/database/DataBase.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 1f8cde2..328742e 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -10,6 +10,7 @@ import java.io.*; public class DataBase { //public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; + public static final int NBCOL =25; public static final String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; public static final String filePath="c:/Users/cocof/Bureau/nouveau_loto.csv"; -- 2.49.1 From ccc3c1885407e6bb09bc7f207692f23ffa89639f Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Thu, 21 Jan 2021 11:38:27 +0100 Subject: [PATCH 13/31] =?UTF-8?q?Creation=20de=20la=20methode=20pour=20del?= =?UTF-8?q?ete=20les=20valeurs=20apr=C3=A8s=202017027,=20Creation=20de=20l?= =?UTF-8?q?a=20methode=20drop=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/myny/database/DataBase.java | 167 +++++++++++++++++- .../java/fr/myny/database/DataBaseTest.java | 12 ++ 2 files changed, 172 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 328742e..d194cf0 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -82,6 +82,7 @@ public class DataBase { Scanner sc = new Scanner(new File(filePath)); sc.useDelimiter(";|\\n"); //sets the delimiter pattern int i=0,j; + long val; String line=sc.nextLine(); line=""; String date, jour, mois, an; @@ -89,7 +90,8 @@ public class DataBase { j=(i% NBCOL)+1; if(j==1) { line=line+'('; - line=line+sc.next().replace(",","."); + val=Long.parseLong(sc.next().replace(",",".")); + line=line+val; line=line+';'; } if(j< NBCOL && j>1) { @@ -201,17 +203,17 @@ public class DataBase { " numero_chance TINYINT,"+ //10 " combinaison_gagnante_en_ordre_croissant varchar(20),"+//11 VARCHAR " nombre_de_gagnant_au_rang1 INTEGER,"+ //12 - " rapport_du_rang1 INTEGER,"+ //13 + " rapport_du_rang1 float(53),"+ //13 " nombre_de_gagnant_au_rang2 INTEGER,"+ //14 - " rapport_du_rang2 INTEGER,"+ //15 + " rapport_du_rang2 float(53),"+ //15 " nombre_de_gagnant_au_rang3 INTEGER,"+ //16 - " rapport_du_rang3 INTEGER,"+ //17 + " rapport_du_rang3 float(53),"+ //17 " nombre_de_gagnant_au_rang4 INTEGER,"+ //18 - " rapport_du_rang4 INTEGER,"+ //19 + " rapport_du_rang4 float(53),"+ //19 " nombre_de_gagnant_au_rang5 INTEGER,"+ //20 - " rapport_du_rang5 INTEGER,"+ //21 + " rapport_du_rang5 float(53),"+ //21 " nombre_de_gagnant_au_rang6 INTEGER,"+ //22 - " rapport_du_rang6 INTEGER,"+ //23 + " rapport_du_rang6 float(53),"+ //23 " numero_jokerplus INTEGER,"+ //24 " devise VARCHAR(10));"; //25 VARCHAR //System.out.println(sql); @@ -433,6 +435,157 @@ public class DataBase { } + public String updateDataBasev2() throws FileNotFoundException { + String sql="INSERT INTO myny.Test_Table" + //le debut de la requete, specifiant laction a effectuer, la table et la db + " (annee_numero_de_tirage, "+ + " jour_de_tirage, "+ + " date_de_tirage,"+ + " date_de_forclusion,"+ + " boule_1 ,"+ + " boule_2 ,"+ + " boule_3 ,"+ + " boule_4 ,"+ + " boule_5 ,"+ + " numero_chance ,"+ + " combinaison_gagnante_en_ordre_croissant ,"+ + " nombre_de_gagnant_au_rang1 ,"+ + " rapport_du_rang1 ,"+ + " nombre_de_gagnant_au_rang2 ,"+ + " rapport_du_rang2 ,"+ + " nombre_de_gagnant_au_rang3 ,"+ + " rapport_du_rang3 ,"+ + " nombre_de_gagnant_au_rang4 ,"+ + " rapport_du_rang4 ,"+ + " nombre_de_gagnant_au_rang5 ,"+ + " rapport_du_rang5 ,"+ + " nombre_de_gagnant_au_rang6 ,"+ + " rapport_du_rang6 ,"+ + " numero_jokerplus ,"+ + " devise ) VALUES \n"; + try { + conn = this.getConnection(); //initialisation de la connexion + if(conn!=null) { //si la co est bonne + Scanner sc = new Scanner(new File(filePath)); //lire le fichier donne + sc.useDelimiter(";|\\n"); //les delimiteurs seront ; et \n + sc.nextLine(); //on ne conserve pas la premiere ligne, contenant les metadonnees + long cpt=0; + Object[] champs; + int i=0,j=0, nbValAj=0; + String date, jour, mois, an; + String line=""; + long anEntre=Long.parseLong(sc.next()); //lecture de l id en haut du tableau(donc le plus grand, cest ce qu on a constate en lisant le csv + //System.out.println("numero en haut du fichier csv :"+anEntre); + Statement stmt = conn.createStatement(); //recuperation du nb de lignes dans la table + ResultSet rs = stmt.executeQuery("SELECT MAX(annee_numero_de_tirage) FROM myny.Test_Table;"); + rs.next(); + long maxvaldb=rs.getLong(1); + //System.out.println("numero max de la db :"+rs.getLong(1)); + /*comme les nombres de la premiere col sont decroissants, le nb le plus grand est lu en premier, + on va donc lire les nombres jusqua arriver a la plus haute valeur entree dans la table. On ne + pourrait probablement pas utiliser cette methode pour remplir la table en entier*/ + while(anEntre>maxvaldb) { + nbValAj++;//des quon rentre dans la boucle, on sait qu'on va devoir mettre a jour la table car cette valeur est>0 + for (i = 0; i < NBCOL; i++) {//on remplit la ligne en effectuant une lecture par col + + j = (i % NBCOL) + 1; + if (j == 1) { + line = line + "(?;";//debut de la ligne a jouter + //champs[cpt++]=anEntre; + //line = line + anEntre; + //line = line + ';';//on met un point virgule mais on le remplacera plus tard + //sc.next(); + } + if (j < NBCOL && j > 1) {//pour chaque colonne, on va faire en sorte de mettre le champ dans la onne mise en fore pour qu'il soit accepté par la db + if (j == 2 || j == 11) { + line = line + "\'" + sc.next().replace(",", ".") + "\',"; + } else if (j == 3 || j == 4) {//pour les col 3 et 4, il s'agit d'une date, on va donc passer dela forme jj-mm-aaaa a la forme aaaa-mm-jj + date = sc.next().replace(",", "."); + jour = date.substring(0, 2); + mois = date.substring(3, 5); + an = date.substring(6, 10); + line = line + "\'" + an + "-" + mois + "-" + jour + "\',"; + } else {//pour les autres col, on va simplement les remplir + line = line + sc.next().replace(",", "."); + line = line + ';'; + } + } + if (j == NBCOL) {//pour la derniere col + line = line + "\'" + sc.next().replace(",", ".") + "\'"; + line = line + ')';//on la remplit + line = line.replaceAll("\\s", "");//on remplace les caracteres qui nous derangent + line = line.replaceAll(";", ","); + anEntre = Long.parseLong(sc.next());//on lit le prochain id de l'entree + if (anEntre > maxvaldb) {//on defini si on doit encore ajouter des lignes a la requete + line = line + ","; + } else {//ou si on doit cloturer la requete + line = line + ";"; + } + //System.out.println(line); + sql = sql + line + "\n";//on ajoute la ligne a la requete + line = ""; + } + } + } + System.out.println(sql); + if (nbValAj>0) {//on effectue la requete si on a des maj a faire + try { + conn = this.getConnection(); + if (conn != null) { + stmt = conn.createStatement(); + stmt.executeQuery(sql); + conn.commit(); + //conn.close(); + System.out.println("update validee"); + } + } catch (SQLException e) { + System.out.println("oskour into update"); + System.out.println(e.getMessage()); + } + } + } + } catch (SQLException e) { + System.out.println("oskour update"); + System.out.println(e.getMessage()); + } + return sql; + } + + public void removeLines() throws FileNotFoundException{ + String sql="delete from myny.Test_Table where annee_numero_de_tirage >2017027"; + try { + conn = this.getConnection(); + if(conn!=null) { + Statement ps = conn.createStatement(); + ps.executeQuery(sql); + conn.commit(); + //conn.close(); + System.out.println("statement cree"); + } + } catch (SQLException e) { + System.out.println("oskour"); + System.out.println(e.getMessage()); + } + + } + + public void dropTable() throws FileNotFoundException{ + String sql="drop table myny.Test_Table"; + try { + conn = this.getConnection(); + if(conn!=null) { + Statement ps = conn.createStatement(); + ps.executeQuery(sql); + conn.commit(); + //conn.close(); + System.out.println("statement cree"); + } + } catch (SQLException e) { + System.out.println("oskour"); + System.out.println(e.getMessage()); + } + + } + diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index 541e6c7..2c74bd3 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -58,4 +58,16 @@ class DataBaseTest { Connection maCo=maDB.getConnection(); assertNotNull(maCo); } + + @Test + public void removeLines() throws FileNotFoundException{ + DataBase maDB=new DataBase(); + maDB.removeLines(); + } + + @Test + public void dropTable() throws FileNotFoundException{ + DataBase maDB=new DataBase(); + maDB.dropTable(); + } } \ No newline at end of file -- 2.49.1 From 0b833a3f648872f946b31ddaf6a04a6ef3b9abdd Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Thu, 21 Jan 2021 16:15:15 +0100 Subject: [PATCH 14/31] ajout d'une methode updatev2 pour ne pas avoir d'injections sql dedans --- src/main/java/fr/myny/database/DataBase.java | 95 ++++++++++++++++--- .../java/fr/myny/database/DataBaseTest.java | 10 ++ 2 files changed, 93 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index d194cf0..e801504 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -203,17 +203,17 @@ public class DataBase { " numero_chance TINYINT,"+ //10 " combinaison_gagnante_en_ordre_croissant varchar(20),"+//11 VARCHAR " nombre_de_gagnant_au_rang1 INTEGER,"+ //12 - " rapport_du_rang1 float(53),"+ //13 + " rapport_du_rang1 float(53),"+ //13 flo " nombre_de_gagnant_au_rang2 INTEGER,"+ //14 - " rapport_du_rang2 float(53),"+ //15 + " rapport_du_rang2 float(53),"+ //15 flo " nombre_de_gagnant_au_rang3 INTEGER,"+ //16 - " rapport_du_rang3 float(53),"+ //17 + " rapport_du_rang3 float(53),"+ //17 flo " nombre_de_gagnant_au_rang4 INTEGER,"+ //18 - " rapport_du_rang4 float(53),"+ //19 + " rapport_du_rang4 float(53),"+ //19 flo " nombre_de_gagnant_au_rang5 INTEGER,"+ //20 - " rapport_du_rang5 float(53),"+ //21 + " rapport_du_rang5 float(53),"+ //21 flo " nombre_de_gagnant_au_rang6 INTEGER,"+ //22 - " rapport_du_rang6 float(53),"+ //23 + " rapport_du_rang6 float(53),"+ //23 flo " numero_jokerplus INTEGER,"+ //24 " devise VARCHAR(10));"; //25 VARCHAR //System.out.println(sql); @@ -436,6 +436,10 @@ public class DataBase { public String updateDataBasev2() throws FileNotFoundException { + //Ligne maL=new Ligne(); + long[][] mesL=new long[4000][NBCOL+1]; + String[][]mesS=new String[4000][NBCOL+1]; + Double[][]mesD=new Double[4000][NBCOL+1]; String sql="INSERT INTO myny.Test_Table" + //le debut de la requete, specifiant laction a effectuer, la table et la db " (annee_numero_de_tirage, "+ " jour_de_tirage, "+ @@ -469,7 +473,7 @@ public class DataBase { sc.useDelimiter(";|\\n"); //les delimiteurs seront ; et \n sc.nextLine(); //on ne conserve pas la premiere ligne, contenant les metadonnees long cpt=0; - Object[] champs; + //Object[] champs; int i=0,j=0, nbValAj=0; String date, jour, mois, an; String line=""; @@ -489,14 +493,47 @@ public class DataBase { j = (i % NBCOL) + 1; if (j == 1) { - line = line + "(?;";//debut de la ligne a jouter + line = line + "(?,";//debut de la ligne a jouter + mesL[nbValAj][j]=anEntre; //champs[cpt++]=anEntre; //line = line + anEntre; //line = line + ';';//on met un point virgule mais on le remplacera plus tard //sc.next(); } if (j < NBCOL && j > 1) {//pour chaque colonne, on va faire en sorte de mettre le champ dans la onne mise en fore pour qu'il soit accepté par la db + line = line + "?,"; if (j == 2 || j == 11) { + mesS[nbValAj][j] = sc.next().replaceAll("\\s", ""); + } else if (j == 3 || j == 4) {//pour les col 3 et 4, il s'agit d'une date, on va donc passer dela forme jj-mm-aaaa a la forme aaaa-mm-jj + date = sc.next().replace(",", "."); + jour = date.substring(0, 2); + mois = date.substring(3, 5); + an = date.substring(6, 10); + mesS[nbValAj][j] = an + "-" + mois + "-" + jour ; + } + else if (j >= 13 && j <= 23 && j % 2 == 1) {//pour les col 3 et 4, il s'agit d'une date, on va donc passer dela forme jj-mm-aaaa a la forme aaaa-mm-jj + mesD[nbValAj][j] = Double.parseDouble(sc.next().replace(",", ".")); + } + else {//pour les autres col, on va simplement les remplir + mesL[nbValAj][j] = Long.parseLong(sc.next().replaceAll("\\s", "")); + } + } + else if (j == NBCOL) {//pour la derniere col + line=line+"?)"; + mesS[nbValAj][j] = sc.next().replaceAll("\\s", ""); + anEntre = Long.parseLong(sc.next());//on lit le prochain id de l'entree + if (anEntre > maxvaldb) {//on defini si on doit encore ajouter des lignes a la requete + line = line + ","; + } else {//ou si on doit cloturer la requete + line = line + ";"; + } + //System.out.println(line); + sql = sql + line + "\n";//on ajoute la ligne a la requete + line = ""; + } + + + /*if (j == 2 || j == 11) { line = line + "\'" + sc.next().replace(",", ".") + "\',"; } else if (j == 3 || j == 4) {//pour les col 3 et 4, il s'agit d'une date, on va donc passer dela forme jj-mm-aaaa a la forme aaaa-mm-jj date = sc.next().replace(",", "."); @@ -508,8 +545,8 @@ public class DataBase { line = line + sc.next().replace(",", "."); line = line + ';'; } - } - if (j == NBCOL) {//pour la derniere col + }*/ + /*if (j == NBCOL) {//pour la derniere col line = line + "\'" + sc.next().replace(",", ".") + "\'"; line = line + ')';//on la remplit line = line.replaceAll("\\s", "");//on remplace les caracteres qui nous derangent @@ -523,10 +560,44 @@ public class DataBase { //System.out.println(line); sql = sql + line + "\n";//on ajoute la ligne a la requete line = ""; - } + }*/ } } System.out.println(sql); + if (nbValAj>0) { + PreparedStatement ps = null; + try { + conn = this.getConnection(); + if (conn != null) { + ps=conn.prepareStatement(sql); + for(int a=1;a<=nbValAj;a++){ + for(int b=1;b<=NBCOL;b++){ + if((b>1&&b<5)||b==11||b==25){ + System.out.println("a: "+a+" et b: "+b); + ps.setString((a-1)*25+b, mesS[a][b]); + + } + else if(j > 12 && j < 24 && j % 2 == 1){ + System.out.println("a: "+a+" et b: "+b); + ps.setString((a-1)*25+b, mesD[a][b]+""); + } + else{ + System.out.println("a: "+a+" et b: "+b); + ps.setString((a-1)*25+b, mesL[a][b]+""); + } + } + } + //conn.close(); + ps.executeQuery(); + System.out.println("update validee"); + } + } catch (SQLException e) { + System.out.println("oskour into update"); + System.out.println(e.getMessage()); + } + + } + /*System.out.println(sql); if (nbValAj>0) {//on effectue la requete si on a des maj a faire try { conn = this.getConnection(); @@ -541,7 +612,7 @@ public class DataBase { System.out.println("oskour into update"); System.out.println(e.getMessage()); } - } + }*/ } } catch (SQLException e) { System.out.println("oskour update"); diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index 2c74bd3..ff12f52 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -52,6 +52,16 @@ class DataBaseTest { } + @Test + void updateDataBasev2() throws FileNotFoundException { + DataBase maDB=new DataBase(); + Connection maCo=maDB.getConnection(); + String requete = maDB.updateDataBasev2(); + System.out.println(requete); + assertNotNull(maCo); + + } + @Test void getConnection() { DataBase maDB=new DataBase(); -- 2.49.1 From 47c62153866b40508c3111047780d3e9e16a6bd1 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Thu, 21 Jan 2021 17:33:26 +0100 Subject: [PATCH 15/31] MAJ fill database sans sql injection --- .idea/dbnavigator.xml | 6 +- src/main/java/fr/myny/database/DataBase.java | 402 ++++++++---------- .../java/fr/myny/database/DataBaseTest.java | 6 +- 3 files changed, 180 insertions(+), 234 deletions(-) diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml index 20d6cbe..122a7bd 100644 --- a/.idea/dbnavigator.xml +++ b/.idea/dbnavigator.xml @@ -23,7 +23,11 @@ - + + + + + diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index e801504..6a78cbd 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -22,162 +22,7 @@ public class DataBase { } - /** - * La methode de remplissage de la base de donnees - */ - public void fillDataBase(){ - /*String sql="INSERT INTO 'myny.Test_Table'" + - " ('annee_numero_de_tirage', "+ - " 'jour_de_tirage', "+ - " 'date_de_tirage',"+ - " 'date_de_forclusion',"+ - " 'boule_1' ,"+ - " 'boule_2' ,"+ - " 'boule_3' ,"+ - " 'boule_4' ,"+ - " 'boule_5' ,"+ - " 'numero_chance' ,"+ - " 'combinaison_gagnante_en_ordre_croissant' ,"+ - " 'nombre_de_gagnant_au_rang1' ,"+ - " 'rapport_du_rang1' ,"+ - " 'nombre_de_gagnant_au_rang2' ,"+ - " 'rapport_du_rang2' ,"+ - " 'nombre_de_gagnant_au_rang3' ,"+ - " 'rapport_du_rang3' ,"+ - " 'nombre_de_gagnant_au_rang4' ,"+ - " 'rapport_du_rang4' ,"+ - " 'nombre_de_gagnant_au_rang5' ,"+ - " 'rapport_du_rang5' ,"+ - " 'nombre_de_gagnant_au_rang6' ,"+ - " 'rapport_du_rang6' ,"+ - " 'numero_jokerplus' ,"+ - " 'devise' ) VALUES";*/ - String sql="INSERT INTO myny.Test_Table" + - " (annee_numero_de_tirage, "+ - " jour_de_tirage, "+ - " date_de_tirage,"+ - " date_de_forclusion,"+ - " boule_1 ,"+ - " boule_2 ,"+ - " boule_3 ,"+ - " boule_4 ,"+ - " boule_5 ,"+ - " numero_chance ,"+ - " combinaison_gagnante_en_ordre_croissant ,"+ - " nombre_de_gagnant_au_rang1 ,"+ - " rapport_du_rang1 ,"+ - " nombre_de_gagnant_au_rang2 ,"+ - " rapport_du_rang2 ,"+ - " nombre_de_gagnant_au_rang3 ,"+ - " rapport_du_rang3 ,"+ - " nombre_de_gagnant_au_rang4 ,"+ - " rapport_du_rang4 ,"+ - " nombre_de_gagnant_au_rang5 ,"+ - " rapport_du_rang5 ,"+ - " nombre_de_gagnant_au_rang6 ,"+ - " rapport_du_rang6 ,"+ - " numero_jokerplus ,"+ - " devise ) VALUES \n"; - try { - Scanner sc = new Scanner(new File(filePath)); - sc.useDelimiter(";|\\n"); //sets the delimiter pattern - int i=0,j; - long val; - String line=sc.nextLine(); - line=""; - String date, jour, mois, an; - while (sc.hasNext()){ - j=(i% NBCOL)+1; - if(j==1) { - line=line+'('; - val=Long.parseLong(sc.next().replace(",",".")); - line=line+val; - line=line+';'; - } - if(j< NBCOL && j>1) { - if (j==2 ||j==11){ - line=line+"\'"+sc.next().replace(",",".")+"\',"; - } - else if (j==3 ||j==4){ - date=sc.next().replace(",","."); - jour=date.substring(0,2); - mois=date.substring(3,5); - an=date.substring(6,10); - line=line+"\'"+an+"-"+mois+"-"+jour+"\',"; - } - else{ - line=line+sc.next().replace(",","."); - line=line+';'; - } - } - if(j== NBCOL) { - line=line+"\'"+sc.next().replace(",",".")+"\'"; - line=line+')'; - line=line.replaceAll("\\s",""); - line = line.replaceAll(";", ","); - if(sc.hasNext()) { - line = line+ ","; - } - else{ - line = line+ ";"; - } - //System.out.println(line); - sql=sql+line; - line=""; - } - i++; - //System.out.println(sc.nextLine()); - //System.out.print(sc.next()); //find and returns the next complete token from this scanner - } - System.out.println(sql); - //System.out.println(sql); - /*CSVReader reader = new CSVReader(new FileReader(filePath)); - String[] nextLine=reader.readNext(); - while ((nextLine = reader.readNext()) != null) { - // nextLine[] is an array of values from the line - for (int j = 0; j < nextLine.length - 1; j++) { - if (j==0){ - sql=sql+"("; - } - sql=sql+nextLine[j]; - if (j==nextLine.length-1){ - sql=sql+"),"; - } - else{ - sql=sql+","; - } - //System.out.println(nextLine[j]); - } - sql=sql+";"; - } - System.out.println(sql); - - conn = DriverManager.getConnection(url); - if(conn!=null) { - Statement stmt = conn.createStatement(); - stmt.executeQuery(sql); - conn.commit(); - System.out.println("statement cree"); - }*/ - } - catch (Exception e){ - System.out.println(e.getMessage()); - } - try { - conn = this.getConnection(); - if(conn!=null) { - Statement stmt = conn.createStatement(); - stmt.executeQuery(sql); - conn.commit(); - //conn.close(); - System.out.println("statement cree"); - } - } catch (SQLException e) { - System.out.println("oskour"); - System.out.println(e.getMessage()); - } - } /** * La methode dimport de donnees depuis la base de donnees @@ -309,6 +154,133 @@ public class DataBase { } + /** + * La methode de remplissage de la base de donnees + */ + public void fillDataBase(){ + int i=0,j, nbValAj=0; + long val; + String line=""; + String date, jour, mois, an; + long[][] mesL=new long[4000][NBCOL+1]; + String[][]mesS=new String[4000][NBCOL+1]; + Double[][]mesD=new Double[4000][NBCOL+1]; + String sql="INSERT INTO myny.Test_Table" + + " (annee_numero_de_tirage, "+ + " jour_de_tirage, "+ + " date_de_tirage,"+ + " date_de_forclusion,"+ + " boule_1 ,"+ + " boule_2 ,"+ + " boule_3 ,"+ + " boule_4 ,"+ + " boule_5 ,"+ + " numero_chance ,"+ + " combinaison_gagnante_en_ordre_croissant ,"+ + " nombre_de_gagnant_au_rang1 ,"+ + " rapport_du_rang1 ,"+ + " nombre_de_gagnant_au_rang2 ,"+ + " rapport_du_rang2 ,"+ + " nombre_de_gagnant_au_rang3 ,"+ + " rapport_du_rang3 ,"+ + " nombre_de_gagnant_au_rang4 ,"+ + " rapport_du_rang4 ,"+ + " nombre_de_gagnant_au_rang5 ,"+ + " rapport_du_rang5 ,"+ + " nombre_de_gagnant_au_rang6 ,"+ + " rapport_du_rang6 ,"+ + " numero_jokerplus ,"+ + " devise ) VALUES \n"; + try { + Scanner sc = new Scanner(new File(filePath)); + sc.useDelimiter(";|\\n"); //sets the delimiter pattern + line=sc.nextLine(); + line=""; + while (sc.hasNext()){ + j=(i% NBCOL)+1; + if(j==1) { + line=line+"(?,"; + mesL[nbValAj][j]=Long.parseLong(sc.next()); + } + if(j< NBCOL && j>1) { + line = line + "?,"; + if (j==2 ||j==11){ + //line=line+"\'"+sc.next().replace(",",".")+"\',"; + mesS[nbValAj][j] = sc.next().replaceAll("\\s", ""); + + } + else if (j==3 ||j==4){ + date=sc.next().replace(",","."); + jour=date.substring(0,2); + mois=date.substring(3,5); + an=date.substring(6,10); + mesS[nbValAj][j]=an+"-"+mois+"-"+jour; + } + else if (j >= 13 && j <= 23 && j % 2 == 1) {//pour les col 3 et 4, il s'agit d'une date, on va donc passer dela forme jj-mm-aaaa a la forme aaaa-mm-jj + mesD[nbValAj][j] = Double.parseDouble(sc.next().replace(",", ".")); + + } + else {//pour les autres col, on va simplement les remplir + mesL[nbValAj][j] = Long.parseLong(sc.next().replaceAll("\\s", "")); + } + } + if(j== NBCOL) { + nbValAj++; + line=line+"?)"; + mesS[nbValAj][j] = sc.next().replaceAll("\\s", ""); + if(sc.hasNext()) { + line = line+ ","; + } + else{ + line = line+ ";"; + } + //System.out.println(line); + sql=sql+line; + line=""; + } + i++; + } + System.out.println(sql); + } + catch (Exception e){ + System.out.println(e.getMessage()); + } + if (nbValAj>0) {//si on a des modifications + PreparedStatement ps = null; + try { + conn = this.getConnection(); + if (conn != null) { + ps=conn.prepareStatement(sql); + for(int a=0;a1&&b<5)||b==11||b==25){ + System.out.println("a: "+a+" et b: "+b); + ps.setString((a)*25+b, mesS[a][b]); + + } + else if(b > 12 && b < 24 && b % 2 == 1){ + System.out.println("a: "+a+" et b: "+b); + if (b == 13) { + System.out.println(mesD[a][b]); + } + ps.setString((a)*25+b, mesD[a][b]+""); + } + else{ + System.out.println("a: "+a+" et b: "+b); + ps.setString((a)*25+b, mesL[a][b]+""); + } + } + } + ps.executeQuery();//puis on execute la requete + System.out.println("update validee"); + } + } catch (SQLException e) { + System.out.println("oskour into update"); + System.out.println(e.getMessage()); + } + } + } + /** * La methode de mise a jour de la base de donnees * @return sql String, contenant la requete SQL @@ -434,12 +406,39 @@ public class DataBase { return sql; } - + /** + * La methode de mise a jour de la base de donnees 2 qui evite les injections sql + * @return sql String, contenant la requete SQL + * @var mesL tableau dans lequel seront stockés tous les long + * @var mesS tableau dans lequel seront stockés tous les String + * @var mesD tableau dans lequel seront stockés tous les Double + * @var sc Scanner, l objet qui servira a lire le fichier csv + * @var line String, ligne contenant l'ajout a effectuer + * @var i int, un compteur de valeurs lues, + * @var j int, qui suit i%NBCOL + * @var a int, un compteur de lignes modifiees + * @var b int, un compteur de champs modifiees + * @var nbValAj int qui augmente si on doit ajouter des lignes + * @var date String, la valeur de la date lue + * @var jour String, le jour lu + * @var mois String, le mois lu + * @var an String, l annee lue + * @var anEntre long, valeur lue pour l annee et le numero de tirage. sert a definir si la valeur est a ajouter dans la table + * @var ps PreparedStatement pour executer la requete sans injection sql + * @var stmt Statement pour executer la requete de depart + */ public String updateDataBasev2() throws FileNotFoundException { //Ligne maL=new Ligne(); + Statement stmt; long[][] mesL=new long[4000][NBCOL+1]; String[][]mesS=new String[4000][NBCOL+1]; Double[][]mesD=new Double[4000][NBCOL+1]; + Scanner sc; + ResultSet rs; + long anEntre; + int i,j, nbValAj=0; + String date, jour, mois, an; + String line=""; String sql="INSERT INTO myny.Test_Table" + //le debut de la requete, specifiant laction a effectuer, la table et la db " (annee_numero_de_tirage, "+ " jour_de_tirage, "+ @@ -467,38 +466,29 @@ public class DataBase { " numero_jokerplus ,"+ " devise ) VALUES \n"; try { - conn = this.getConnection(); //initialisation de la connexion - if(conn!=null) { //si la co est bonne - Scanner sc = new Scanner(new File(filePath)); //lire le fichier donne + conn = this.getConnection(); //initialisation de la connexion + if(conn!=null) { //si la co est bonne + sc = new Scanner(new File(filePath)); //lire le fichier donne sc.useDelimiter(";|\\n"); //les delimiteurs seront ; et \n sc.nextLine(); //on ne conserve pas la premiere ligne, contenant les metadonnees - long cpt=0; - //Object[] champs; - int i=0,j=0, nbValAj=0; - String date, jour, mois, an; - String line=""; - long anEntre=Long.parseLong(sc.next()); //lecture de l id en haut du tableau(donc le plus grand, cest ce qu on a constate en lisant le csv - //System.out.println("numero en haut du fichier csv :"+anEntre); - Statement stmt = conn.createStatement(); //recuperation du nb de lignes dans la table - ResultSet rs = stmt.executeQuery("SELECT MAX(annee_numero_de_tirage) FROM myny.Test_Table;"); + anEntre=Long.parseLong(sc.next()); //lecture de l id en haut du tableau(donc le plus grand, cest ce qu on a constate en lisant le csv + stmt = conn.createStatement(); //recuperation du nb de lignes dans la table + rs = stmt.executeQuery("SELECT MAX(annee_numero_de_tirage) FROM myny.Test_Table;"); rs.next(); long maxvaldb=rs.getLong(1); - //System.out.println("numero max de la db :"+rs.getLong(1)); + if (maxvaldb<0){ + maxvaldb=0; + } /*comme les nombres de la premiere col sont decroissants, le nb le plus grand est lu en premier, on va donc lire les nombres jusqua arriver a la plus haute valeur entree dans la table. On ne pourrait probablement pas utiliser cette methode pour remplir la table en entier*/ - while(anEntre>maxvaldb) { + while(anEntre>maxvaldb&&sc.hasNext()) { nbValAj++;//des quon rentre dans la boucle, on sait qu'on va devoir mettre a jour la table car cette valeur est>0 for (i = 0; i < NBCOL; i++) {//on remplit la ligne en effectuant une lecture par col - j = (i % NBCOL) + 1; if (j == 1) { line = line + "(?,";//debut de la ligne a jouter mesL[nbValAj][j]=anEntre; - //champs[cpt++]=anEntre; - //line = line + anEntre; - //line = line + ';';//on met un point virgule mais on le remplacera plus tard - //sc.next(); } if (j < NBCOL && j > 1) {//pour chaque colonne, on va faire en sorte de mettre le champ dans la onne mise en fore pour qu'il soit accepté par la db line = line + "?,"; @@ -531,53 +521,23 @@ public class DataBase { sql = sql + line + "\n";//on ajoute la ligne a la requete line = ""; } - - - /*if (j == 2 || j == 11) { - line = line + "\'" + sc.next().replace(",", ".") + "\',"; - } else if (j == 3 || j == 4) {//pour les col 3 et 4, il s'agit d'une date, on va donc passer dela forme jj-mm-aaaa a la forme aaaa-mm-jj - date = sc.next().replace(",", "."); - jour = date.substring(0, 2); - mois = date.substring(3, 5); - an = date.substring(6, 10); - line = line + "\'" + an + "-" + mois + "-" + jour + "\',"; - } else {//pour les autres col, on va simplement les remplir - line = line + sc.next().replace(",", "."); - line = line + ';'; - } - }*/ - /*if (j == NBCOL) {//pour la derniere col - line = line + "\'" + sc.next().replace(",", ".") + "\'"; - line = line + ')';//on la remplit - line = line.replaceAll("\\s", "");//on remplace les caracteres qui nous derangent - line = line.replaceAll(";", ","); - anEntre = Long.parseLong(sc.next());//on lit le prochain id de l'entree - if (anEntre > maxvaldb) {//on defini si on doit encore ajouter des lignes a la requete - line = line + ","; - } else {//ou si on doit cloturer la requete - line = line + ";"; - } - //System.out.println(line); - sql = sql + line + "\n";//on ajoute la ligne a la requete - line = ""; - }*/ } } System.out.println(sql); - if (nbValAj>0) { + if (nbValAj>0) {//si on a des modifications PreparedStatement ps = null; try { conn = this.getConnection(); if (conn != null) { ps=conn.prepareStatement(sql); - for(int a=1;a<=nbValAj;a++){ - for(int b=1;b<=NBCOL;b++){ + for(int a=1;a<=nbValAj;a++){//pour chaque case de chaque ligne ajoutée, on va ajouter la valeur + for(int b=1;b<=NBCOL;b++){//dans la declaration preparee, pour eviter les injections sql if((b>1&&b<5)||b==11||b==25){ System.out.println("a: "+a+" et b: "+b); ps.setString((a-1)*25+b, mesS[a][b]); } - else if(j > 12 && j < 24 && j % 2 == 1){ + else if(b > 12 && b < 24 && b % 2 == 1){ System.out.println("a: "+a+" et b: "+b); ps.setString((a-1)*25+b, mesD[a][b]+""); } @@ -587,32 +547,14 @@ public class DataBase { } } } - //conn.close(); - ps.executeQuery(); + ps.executeQuery();//puis on execute la requete System.out.println("update validee"); } } catch (SQLException e) { System.out.println("oskour into update"); System.out.println(e.getMessage()); } - } - /*System.out.println(sql); - if (nbValAj>0) {//on effectue la requete si on a des maj a faire - try { - conn = this.getConnection(); - if (conn != null) { - stmt = conn.createStatement(); - stmt.executeQuery(sql); - conn.commit(); - //conn.close(); - System.out.println("update validee"); - } - } catch (SQLException e) { - System.out.println("oskour into update"); - System.out.println(e.getMessage()); - } - }*/ } } catch (SQLException e) { System.out.println("oskour update"); @@ -621,8 +563,8 @@ public class DataBase { return sql; } - public void removeLines() throws FileNotFoundException{ - String sql="delete from myny.Test_Table where annee_numero_de_tirage >2017027"; + public void removeLines(int i) throws FileNotFoundException{ + String sql="delete from myny.Test_Table where annee_numero_de_tirage >"+i; try { conn = this.getConnection(); if(conn!=null) { diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index ff12f52..23d2d52 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -16,14 +16,14 @@ class DataBaseTest { DataBase maDB=new DataBase(); Connection maCo=maDB.getConnection(); assertNotNull(maCo); - //maDB.fillDataBase(); + maDB.fillDataBase(); Statement stmt= maDB.conn.createStatement(); ResultSet rs=stmt.executeQuery("SELECT Count(*) From myny.Test_Table"); rs.next(); long nbcolret= rs.getLong(1); //System.out.println("nb lignes (changer la ligne juste en dessous si on modifie le nb de lignes): "+rs.getInt("total")); System.out.println("nb lignes (changer la ligne juste en dessous si on modifie le nb de lignes): "+rs.getLong(1)); - assertEquals(1317,rs.getLong(1)); + assertEquals(1321,rs.getLong(1)); } @Test @@ -72,7 +72,7 @@ class DataBaseTest { @Test public void removeLines() throws FileNotFoundException{ DataBase maDB=new DataBase(); - maDB.removeLines(); + maDB.removeLines(0); } @Test -- 2.49.1 From 7af2688494b3db0e23ca6dfa297e9cf90d623286 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Thu, 21 Jan 2021 19:48:08 +0100 Subject: [PATCH 16/31] =?UTF-8?q?Toutes=20les=20m=C3=A9thodes=20finies=20f?= =?UTF-8?q?onctionnelles,=20commentees,=20avec=20la=20javadoc,=20v=C3=A9ri?= =?UTF-8?q?fi=C3=A9es=20une=20=C3=A0=20une,=20et=20les=20tests=20valides?= =?UTF-8?q?=20(pour=20le=20cas=20utilis=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/myny/database/DataBase.java | 422 +++++++++--------- .../java/fr/myny/database/DataBaseTest.java | 53 ++- 2 files changed, 252 insertions(+), 223 deletions(-) diff --git a/src/main/java/fr/myny/database/DataBase.java b/src/main/java/fr/myny/database/DataBase.java index 6a78cbd..6afd569 100644 --- a/src/main/java/fr/myny/database/DataBase.java +++ b/src/main/java/fr/myny/database/DataBase.java @@ -10,162 +10,125 @@ import java.io.*; public class DataBase { //public static String url="jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"; - - public static final int NBCOL =25; - public static final String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*"; - public static final String filePath="c:/Users/cocof/Bureau/nouveau_loto.csv"; - Connection conn; + public static final int NBCOL =25;//le nombre de coldu fichier csv + public static final String url="jdbc:mariadb://phpmyadmin.vachot.fr:3306?db=myny&user=mynynicolas&password=Bw0po64*";//l'acces à la db + Connection conn;//la connexion a la db /** * Le constructeur de DataBase */ public DataBase(){ } - + /** + * La methode de connection + * @return conn la connection a la db + */ + public Connection getConnection() { + conn = null; + try { + conn = DriverManager.getConnection(url); + //conn = DriverManager.getConnection("jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"); + //conn = DriverManager.getConnection("jdbc:mariadb://phpmyadmin.vachot.fr:3306/myny?user=mynynicolas&password=Bw0po64*"); + //conn = DriverManager.getConnection("jdbc:mariadb:../../../../../../test.db"); + if(conn!=null) { + System.out.println("Connecte a la db"); + System.out.println(conn); + } + }catch(SQLException e) { + System.out.println("getConnection on a des pb:" + e.getMessage()); + } + return conn; + } /** - * La methode dimport de donnees depuis la base de donnees + * La methode d import de donnees depuis la base de donnees */ public void importDataBase(){ } /** - * La methode de creation de la base de donnees + * La methode de creation de la table + * stmt Statement la variable pour créer la declaration + * sql String la requete + * @return res, int le resultat de la requete (nb de ligne affectees) */ - public void createDataBase() { - String sql="CREATE TABLE IF NOT EXISTS myny.Test_Table ("+ - " annee_numero_de_tirage INTEGER,"+ //1 - " jour_de_tirage VARCHAR(10),"+ //2 VARCHAR - " date_de_tirage DATE,"+ //3 DATE - " date_de_forclusion DATE,"+ //4 DATE - " boule_1 TINYINT,"+ //5 - " boule_2 TINYINT,"+ //6 - " boule_3 TINYINT,"+ //7 - " boule_4 TINYINT,"+ //8 - " boule_5 TINYINT,"+ //9 - " numero_chance TINYINT,"+ //10 - " combinaison_gagnante_en_ordre_croissant varchar(20),"+//11 VARCHAR - " nombre_de_gagnant_au_rang1 INTEGER,"+ //12 - " rapport_du_rang1 float(53),"+ //13 flo - " nombre_de_gagnant_au_rang2 INTEGER,"+ //14 - " rapport_du_rang2 float(53),"+ //15 flo - " nombre_de_gagnant_au_rang3 INTEGER,"+ //16 - " rapport_du_rang3 float(53),"+ //17 flo - " nombre_de_gagnant_au_rang4 INTEGER,"+ //18 - " rapport_du_rang4 float(53),"+ //19 flo - " nombre_de_gagnant_au_rang5 INTEGER,"+ //20 - " rapport_du_rang5 float(53),"+ //21 flo - " nombre_de_gagnant_au_rang6 INTEGER,"+ //22 - " rapport_du_rang6 float(53),"+ //23 flo - " numero_jokerplus INTEGER,"+ //24 - " devise VARCHAR(10));"; //25 VARCHAR + public int createTable() { + int res=-1; + Statement stmt; + String sql="CREATE TABLE IF NOT EXISTS myny.Test_Table ("+ //declaration de la table, de ses colonnes et de leur type et leur taille (on aurai pu ajouter des param supplementaires) + " annee_numero_de_tirage INTEGER,"+ //1 long + " jour_de_tirage VARCHAR(10),"+ //2 String + " date_de_tirage DATE,"+ //3 String + " date_de_forclusion DATE,"+ //4 String + " boule_1 TINYINT,"+ //5 long + " boule_2 TINYINT,"+ //6 long + " boule_3 TINYINT,"+ //7 long + " boule_4 TINYINT,"+ //8 long + " boule_5 TINYINT,"+ //9 long + " numero_chance TINYINT,"+ //10 long + " combinaison_gagnante_en_ordre_croissant varchar(20),"+//11 String + " nombre_de_gagnant_au_rang1 INTEGER,"+ //12 long + " rapport_du_rang1 float(53),"+ //13 double + " nombre_de_gagnant_au_rang2 INTEGER,"+ //14 long + " rapport_du_rang2 float(53),"+ //15 double + " nombre_de_gagnant_au_rang3 INTEGER,"+ //16 long + " rapport_du_rang3 float(53),"+ //17 double + " nombre_de_gagnant_au_rang4 INTEGER,"+ //18 long + " rapport_du_rang4 float(53),"+ //19 double + " nombre_de_gagnant_au_rang5 INTEGER,"+ //20 long + " rapport_du_rang5 float(53),"+ //21 double + " nombre_de_gagnant_au_rang6 INTEGER,"+ //22 long + " rapport_du_rang6 float(53),"+ //23 double + " numero_jokerplus INTEGER,"+ //24 long + " devise VARCHAR(10));"; //25 String //System.out.println(sql); try { - conn = DriverManager.getConnection(url); + conn = DriverManager.getConnection(url); //connection a la db if(conn!=null) { - Statement stmt = conn.createStatement(); - stmt.executeQuery(sql); + stmt = conn.createStatement(); //creation de la declaration + res=stmt.executeUpdate(sql); //execution de la declaration + //stmt.executeQuery(sql); conn.commit(); //conn.close(); System.out.println("statement cree"); } } catch (SQLException e) { - System.out.println("oskour"); + System.out.println("create table probleme, verifier si le pb ne vient pas de executeupdate au lieu executequery"); System.out.println(e.getMessage()); } - /*try(Statement mySt = conn.createStatement()){ - mySt.execute(//"CREATE SCHEMA IF NOT EXISTS Connection;"+ - "CREATE TABLE IF NOT EXISTS myny.Test_Table ("+ - "annee_numero_de_tirage INTEGER,"+ - "jour_de_tirage CHAR(10),"+ - "date_de_tirage DATE,"+ - "date_de_forclusion DATE,"+ - "boule_1 TINYINT,"+ - "boule_2 TINYINT,"+ - "boule_3 TINYINT,"+ - "boule_4 TINYINT,"+ - "boule_5 TINYINT,"+ - "numero_chance TINYINT,"+ - "combinaison_gagnante_en_ordre_croissantchar(20),"+ - "nombre_de_gagnant_au_rang1 INTEGER,"+ - "rapport_du_rang1 INTEGER,"+ - "nombre_de_gagnant_au_rang2 INTEGER,"+ - "rapport_du_rang2 INTEGER,"+ - "nombre_de_gagnant_au_rang3 INTEGER,"+ - "rapport_du_rang3 INTEGER,"+ - "nombre_de_gagnant_au_rang4 INTEGER,"+ - "rapport_du_rang4 INTEGER,"+ - "nombre_de_gagnant_au_rang5 INTEGER,"+ - "rapport_du_rang5 INTEGER,"+ - "nombre_de_gagnant_au_rang6 INTEGER,"+ - "rapport_du_rang6 INTEGER,"+ - "numero_jokerplus INTEGER,"+ - "deviseCHAR(10));"); - conn.commit(); - //mySt.close(); - //conn.close(); - } - catch(Exception e){ - System.out.println(e); - } - finally { - }*/ - /* - try { - PreparedStatement preparedStatement = connexion.prepareStatement("INSERT INTO noms(nom, prenom) VALUES(?, ?);"); - preparedStatement.setString(1, utilisateur.getNom()); - preparedStatement.setString(2, utilisateur.getPrenom()); - - preparedStatement.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - }*/ - // try { - // Class.forName("com.mysql.jdbc.Driver"); - // } - // catch (ClassNotFoundException e) { - // } - // - // try { - // conn = DriverManager.getConnection("jdbc:mysql://localhost:3306"); - // } catch (SQLException e) { - // System.out.println("oskour " +e.getStackTrace()); - // } - // - // Statement statement = null; - // ResultSet resultat = null; - // try { - // statement = conn.createStatement(); - // - // // Exécution de la requête - // resultat = statement.executeQuery("SELECT nom, prenom FROM noms;"); - // - // // Récupération des données - // while (resultat.next()) { - // String nom = resultat.getString("nom"); - // String prenom = resultat.getString("prenom"); - // } - // } - // catch (SQLException e) { - // System.out.println(e); - // } + return res; } /** * La methode de remplissage de la base de donnees + * line String la ligne a ajouter + * i int, un compteur de valeurs lues, + * j int, qui suit i%NBCOL + * nbValAj int qui augmente si on doit ajouter des lignes + * date String, la valeur de la date lue + * jour String, le jour lu + * mois String, le mois lu + * an String, l annee lue + * mesL tableau dans lequel seront stockés tous les long + * mesS tableau dans lequel seront stockés tous les String + * mesD tableau dans lequel seront stockés tous les Double + * sc Scanner, l objet qui servira a lire le fichier csv + * @param filePath String le fichier et son chemin + * @return res int le resultat de la requete(nb de ligne affectees) */ - public void fillDataBase(){ + public int fillTable(String filePath){ + int res=-1; + Scanner sc; int i=0,j, nbValAj=0; - long val; String line=""; String date, jour, mois, an; long[][] mesL=new long[4000][NBCOL+1]; String[][]mesS=new String[4000][NBCOL+1]; Double[][]mesD=new Double[4000][NBCOL+1]; - String sql="INSERT INTO myny.Test_Table" + + String sql="INSERT INTO myny.Test_Table" +//definit la requete " (annee_numero_de_tirage, "+ " jour_de_tirage, "+ " date_de_tirage,"+ @@ -192,11 +155,10 @@ public class DataBase { " numero_jokerplus ,"+ " devise ) VALUES \n"; try { - Scanner sc = new Scanner(new File(filePath)); - sc.useDelimiter(";|\\n"); //sets the delimiter pattern - line=sc.nextLine(); - line=""; - while (sc.hasNext()){ + sc = new Scanner(new File(filePath));//lire le fichier csv + sc.useDelimiter(";|\\n"); //definit les separateurs utilisés + sc.nextLine();//passe la premiere ligne, les metadonnees + while (sc.hasNext()){//tant qu'on a des champs non-vides, on va remplir la ligne et les cases specifiques des tableaux a 2 dim correspondant au champ lu j=(i% NBCOL)+1; if(j==1) { line=line+"(?,"; @@ -246,7 +208,7 @@ public class DataBase { System.out.println(e.getMessage()); } if (nbValAj>0) {//si on a des modifications - PreparedStatement ps = null; + PreparedStatement ps; try { conn = this.getConnection(); if (conn != null) { @@ -256,7 +218,6 @@ public class DataBase { if((b>1&&b<5)||b==11||b==25){ System.out.println("a: "+a+" et b: "+b); ps.setString((a)*25+b, mesS[a][b]); - } else if(b > 12 && b < 24 && b % 2 == 1){ System.out.println("a: "+a+" et b: "+b); @@ -271,32 +232,44 @@ public class DataBase { } } } - ps.executeQuery();//puis on execute la requete + res=ps.executeUpdate(); + //ps.executeQuery();//puis on execute la requete System.out.println("update validee"); } } catch (SQLException e) { - System.out.println("oskour into update"); + System.out.println("filldatebase probleme, verifier si le pb ne viens pas de executeupdate au lieu executequery"); System.out.println(e.getMessage()); } } + return res; } /** * La methode de mise a jour de la base de donnees - * @return sql String, contenant la requete SQL - * @var sc Scanner, l objet qui servira a lire le fichier csv - * @var line String, ligne contenant l'ajout a effectuer - * @var i int, un compteur de valeurs lues, - * @var j int, qui suit i%NBCOL - * @var nbValAj int qui augmente si on doit ajouter des lignes - * @var date String, la valeur de la date lue - * @var jour String, le jour lu - * @var mois String, le mois lu - * @var an String, l annee lue - * @var anEntre long, valeur lue pour l annee et le numero de tirage. sert a definir si la valeur est a ajouter dans la table + * @return res int, le resultat de la requete(nb de ligne affectees) + * sc Scanner, l objet qui servira a lire le fichier csv + * line String, ligne contenant l'ajout a effectuer + * i int, un compteur de valeurs lues, + * j int, qui suit i%NBCOL + * nbValAj int qui augmente si on doit ajouter des lignes + * date String, la valeur de la date lue + * jour String, le jour lu + * mois String, le mois lu + * an String, l annee lue + * anEntre long, valeur lue pour l annee et le numero de tirage. sert a definir si la valeur est a ajouter dans la tabl + * @deprecated */ - public String updateDataBase() throws FileNotFoundException { - String sql="INSERT INTO myny.Test_Table" + //le debut de la requete, specifiant laction a effectuer, la table et la db + public int updateTable(String filePath) throws FileNotFoundException { + ResultSet rs=null; + Scanner sc; + int res=-1; + int i,j, nbValAj=0; + String date, jour, mois, an; + String line=""; + long anEntre; + Statement stmt; + long maxvaldb; + String sql="INSERT INTO myny.Test_Table" + //le debut de la requete, specifiant laction a effectuer, la table et la db " (annee_numero_de_tirage, "+ " jour_de_tirage, "+ " date_de_tirage,"+ @@ -325,18 +298,15 @@ public class DataBase { try { conn = this.getConnection(); //initialisation de la connexion if(conn!=null) { //si la co est bonne - Scanner sc = new Scanner(new File(filePath)); //lire le fichier donne + sc = new Scanner(new File(filePath)); //lire le fichier donne sc.useDelimiter(";|\\n"); //les delimiteurs seront ; et \n sc.nextLine(); //on ne conserve pas la premiere ligne, contenant les metadonnees - int i=0,j=0, nbValAj=0; - String date, jour, mois, an; - String line=""; - long anEntre=Long.parseLong(sc.next()); //lecture de l id en haut du tableau(donc le plus grand, cest ce qu on a constate en lisant le csv + anEntre=Long.parseLong(sc.next()); //lecture de l id en haut du tableau(donc le plus grand, cest ce qu on a constate en lisant le csv //System.out.println("numero en haut du fichier csv :"+anEntre); - Statement stmt = conn.createStatement(); //recuperation du nb de lignes dans la table - ResultSet rs = stmt.executeQuery("SELECT MAX(annee_numero_de_tirage) FROM myny.Test_Table;"); + stmt = conn.createStatement(); //recuperation du nb de lignes dans la table + rs = stmt.executeQuery("SELECT MAX(annee_numero_de_tirage) FROM myny.Test_Table;"); rs.next(); - long maxvaldb=rs.getLong(1); + maxvaldb=rs.getLong(1); //System.out.println("numero max de la db :"+rs.getLong(1)); /*comme les nombres de la premiere col sont decroissants, le nb le plus grand est lu en premier, on va donc lire les nombres jusqua arriver a la plus haute valeur entree dans la table. On ne @@ -353,20 +323,20 @@ public class DataBase { } if (j < NBCOL && j > 1) {//pour chaque colonne, on va faire en sorte de mettre le champ dans la onne mise en fore pour qu'il soit accepté par la db if (j == 2 || j == 11) { - line = line + "\'" + sc.next().replace(",", ".") + "\',"; + line = line + "'" + sc.next().replace(",", ".") + "',"; } else if (j == 3 || j == 4) {//pour les col 3 et 4, il s'agit d'une date, on va donc passer dela forme jj-mm-aaaa a la forme aaaa-mm-jj date = sc.next().replace(",", "."); jour = date.substring(0, 2); mois = date.substring(3, 5); an = date.substring(6, 10); - line = line + "\'" + an + "-" + mois + "-" + jour + "\',"; + line = line + "'" + an + "-" + mois + "-" + jour + "',"; } else {//pour les autres col, on va simplement les remplir line = line + sc.next().replace(",", "."); line = line + ';'; } } if (j == NBCOL) {//pour la derniere col - line = line + "\'" + sc.next().replace(",", ".") + "\'"; + line = line + "'" + sc.next().replace(",", ".") + "'"; line = line + ')';//on la remplit line = line.replaceAll("\\s", "");//on remplace les caracteres qui nous derangent line = line.replaceAll(";", ","); @@ -388,53 +358,55 @@ public class DataBase { conn = this.getConnection(); if (conn != null) { stmt = conn.createStatement(); - stmt.executeQuery(sql); + res=stmt.executeUpdate(sql); + //stmt.executeQuery(sql); conn.commit(); //conn.close(); System.out.println("update validee"); } } catch (SQLException e) { - System.out.println("oskour into update"); + System.out.println("updateDataBase probleme"); System.out.println(e.getMessage()); } } } } catch (SQLException e) { - System.out.println("oskour update"); + System.out.println("updateDataBase probleme"); System.out.println(e.getMessage()); } - return sql; + return res; } /** * La methode de mise a jour de la base de donnees 2 qui evite les injections sql - * @return sql String, contenant la requete SQL - * @var mesL tableau dans lequel seront stockés tous les long - * @var mesS tableau dans lequel seront stockés tous les String - * @var mesD tableau dans lequel seront stockés tous les Double - * @var sc Scanner, l objet qui servira a lire le fichier csv - * @var line String, ligne contenant l'ajout a effectuer - * @var i int, un compteur de valeurs lues, - * @var j int, qui suit i%NBCOL - * @var a int, un compteur de lignes modifiees - * @var b int, un compteur de champs modifiees - * @var nbValAj int qui augmente si on doit ajouter des lignes - * @var date String, la valeur de la date lue - * @var jour String, le jour lu - * @var mois String, le mois lu - * @var an String, l annee lue - * @var anEntre long, valeur lue pour l annee et le numero de tirage. sert a definir si la valeur est a ajouter dans la table - * @var ps PreparedStatement pour executer la requete sans injection sql - * @var stmt Statement pour executer la requete de depart + * @return rs, int, le resultat de la requete (nb de lignes affectees) + * mesL tableau dans lequel seront stockés tous les long + * mesS tableau dans lequel seront stockés tous les String + * mesD tableau dans lequel seront stockés tous les Double + * sc Scanner, l objet qui servira a lire le fichier csv + * line String, ligne contenant l'ajout a effectuer + * i int, un compteur de valeurs lues, + * j int, qui suit i%NBCOL + * a int, un compteur de lignes modifiees + * b int, un compteur de champs modifiees + * nbValAj int qui augmente si on doit ajouter des lignes + * date String, la valeur de la date lue + * jour String, le jour lu + * mois String, le mois lu + * an String, l annee lue + * anEntre long, valeur lue pour l annee et le numero de tirage. sert a definir si la valeur est a ajouter dans la table + * ps PreparedStatement pour executer la requete sans injection sql + * stmt Statement pour executer la requete de depart */ - public String updateDataBasev2() throws FileNotFoundException { + public int updateTablev2(String filePath) throws FileNotFoundException { //Ligne maL=new Ligne(); + ResultSet rs=null; + int res=-1; Statement stmt; long[][] mesL=new long[4000][NBCOL+1]; String[][]mesS=new String[4000][NBCOL+1]; Double[][]mesD=new Double[4000][NBCOL+1]; Scanner sc; - ResultSet rs; long anEntre; int i,j, nbValAj=0; String date, jour, mois, an; @@ -525,7 +497,7 @@ public class DataBase { } System.out.println(sql); if (nbValAj>0) {//si on a des modifications - PreparedStatement ps = null; + PreparedStatement ps; try { conn = this.getConnection(); if (conn != null) { @@ -535,7 +507,6 @@ public class DataBase { if((b>1&&b<5)||b==11||b==25){ System.out.println("a: "+a+" et b: "+b); ps.setString((a-1)*25+b, mesS[a][b]); - } else if(b > 12 && b < 24 && b % 2 == 1){ System.out.println("a: "+a+" et b: "+b); @@ -547,78 +518,119 @@ public class DataBase { } } } - ps.executeQuery();//puis on execute la requete + res=ps.executeUpdate();//puis on execute la requete + //res=ps.executeQuery();//puis on execute la requete System.out.println("update validee"); } } catch (SQLException e) { - System.out.println("oskour into update"); + System.out.println("updateDataBasev2 probleme"); System.out.println(e.getMessage()); } } } } catch (SQLException e) { - System.out.println("oskour update"); + System.out.println("updateDataBasev2 probleme, verifier si le pb ne vient pas de executeupdate au lie de executequery"); System.out.println(e.getMessage()); } - return sql; + return res; } - public void removeLines(int i) throws FileNotFoundException{ + /** + * la methode de suppression des lignes strictement supérieures a la valeur i dans annee_numero_de_tirage + * @param i la valeur de reference + * @return res, int le resultat de la requete (nb de lignes affectees) + */ + public int removeMultiplesLines(int i){ + int res=-1; String sql="delete from myny.Test_Table where annee_numero_de_tirage >"+i; try { conn = this.getConnection(); if(conn!=null) { Statement ps = conn.createStatement(); - ps.executeQuery(sql); + res=ps.executeUpdate(sql); + //ps.executeQuery(sql); conn.commit(); //conn.close(); System.out.println("statement cree"); } } catch (SQLException e) { - System.out.println("oskour"); + System.out.println("removeLines probleme"); System.out.println(e.getMessage()); } - + return res; } - public void dropTable() throws FileNotFoundException{ - String sql="drop table myny.Test_Table"; + /** + * la methode de selection de la ligne ayant la valeur i dans annee_numero_de_tirage + * @param i la valeur de reference + * @return rs, ResultSet le resultat de la requete + */ + public ResultSet showLine(int i){ + ResultSet rs=null; + String sql="select * from myny.Test_Table where annee_numero_de_tirage ="+i; try { conn = this.getConnection(); if(conn!=null) { Statement ps = conn.createStatement(); - ps.executeQuery(sql); + rs=ps.executeQuery(sql); conn.commit(); //conn.close(); System.out.println("statement cree"); } } catch (SQLException e) { - System.out.println("oskour"); + System.out.println("removeLine probleme"); System.out.println(e.getMessage()); } - + return rs; } - - - /** - * La methode de connection + * la methode de suppression de la ligne ayant la valeur i dans annee_numero_de_tirage + * @param i la valeur de reference + * @return res, int le resultat de la requete(nb de lignes affectees) */ - public Connection getConnection() { - conn = null; + public int removeLine(int i){ + int res=-1; + String sql="delete from myny.Test_Table where annee_numero_de_tirage ="+i; try { - conn = DriverManager.getConnection(url); - //conn = DriverManager.getConnection("jdbc:mariadb://vachot.fr:3306?user=mynynicolas&password=Bw0po64*"); - //conn = DriverManager.getConnection("jdbc:mariadb://phpmyadmin.vachot.fr:3306/myny?user=mynynicolas&password=Bw0po64*"); - //conn = DriverManager.getConnection("jdbc:mariadb:../../../../../../test.db"); + conn = this.getConnection(); if(conn!=null) { - System.out.println("Connected to database"); - System.out.println(conn); + Statement ps = conn.createStatement(); + res=ps.executeUpdate(sql); + //res=ps.executeQuery(sql); + conn.commit(); + //conn.close(); + System.out.println("statement cree"); } - }catch(SQLException e) { - System.out.println("on a des pb:" + e.getMessage()); + } catch (SQLException e) { + System.out.println("removeLine probleme, voir si le pb ne vient pas d'execute query et executeupdate"); + System.out.println(e.getMessage()); } - return conn; + return res; } + + /** + * La methode pour supprimer la table entiere + * @return res int le resultat de la requete(nb de lignes affectees) + */ + public int dropTable(){ + String sql="drop table myny.Test_Table"; + int res=-1; + try { + conn = this.getConnection(); + if(conn!=null) { + Statement ps = conn.createStatement(); + //rs=ps.executeQuery(sql); + res=ps.executeUpdate(sql); + conn.commit(); + //conn.close(); + System.out.println("statement cree"); + } + } catch (SQLException e) { + System.out.println("dropTable probleme, voir si le pb ne vient pas d'execute query et executeupdate"); + System.out.println(e.getMessage()); + } + return res; + } + } diff --git a/src/test/java/fr/myny/database/DataBaseTest.java b/src/test/java/fr/myny/database/DataBaseTest.java index 23d2d52..78abf23 100644 --- a/src/test/java/fr/myny/database/DataBaseTest.java +++ b/src/test/java/fr/myny/database/DataBaseTest.java @@ -3,20 +3,20 @@ package fr.myny.database; import org.junit.jupiter.api.Test; import java.sql.*; -import java.util.*; import java.io.*; import static org.junit.jupiter.api.Assertions.*; -import fr.myny.database.*; class DataBaseTest { - Connection connexion; + Connection maCo; + public static final String FILEPATH="c:/Users/cocof/Bureau/nouveau_loto.csv"; @Test void fillDataBase() throws SQLException { DataBase maDB=new DataBase(); - Connection maCo=maDB.getConnection(); + maCo=maDB.getConnection(); assertNotNull(maCo); - maDB.fillDataBase(); + int res= maDB.fillTable(FILEPATH); + System.out.println(res); Statement stmt= maDB.conn.createStatement(); ResultSet rs=stmt.executeQuery("SELECT Count(*) From myny.Test_Table"); rs.next(); @@ -31,9 +31,9 @@ class DataBaseTest { } @Test - void createDataBase() throws SQLException { + void createTable() throws SQLException { DataBase maDB=new DataBase(); - maDB.createDataBase(); + maDB.createTable(); Statement stmt= maDB.conn.createStatement(); ResultSet rs=stmt.executeQuery("Select * From myny.Test_Table"); ResultSetMetaData rsmd =rs.getMetaData(); @@ -43,21 +43,21 @@ class DataBaseTest { } @Test - void updateDataBase() throws FileNotFoundException { + void updateTable() throws FileNotFoundException, SQLException { DataBase maDB=new DataBase(); - Connection maCo=maDB.getConnection(); - String requete = maDB.updateDataBase(); - System.out.println(requete); + maCo=maDB.getConnection(); + int res = maDB.updateTable(FILEPATH); + System.out.println(res); assertNotNull(maCo); } @Test - void updateDataBasev2() throws FileNotFoundException { + void updateTablev2() throws FileNotFoundException, SQLException { DataBase maDB=new DataBase(); - Connection maCo=maDB.getConnection(); - String requete = maDB.updateDataBasev2(); - System.out.println(requete); + maCo=maDB.getConnection(); + int res = maDB.updateTablev2(FILEPATH); + System.out.println(res); assertNotNull(maCo); } @@ -65,14 +65,31 @@ class DataBaseTest { @Test void getConnection() { DataBase maDB=new DataBase(); - Connection maCo=maDB.getConnection(); + maCo=maDB.getConnection(); assertNotNull(maCo); } + @Test + public void showLine() throws SQLException { + DataBase maDB=new DataBase(); + ResultSet rs=maDB.showLine(2017001); + rs.next(); + for (int i=1;i<26;i++) { + System.out.print(rs.getObject(i)+", "); + } + } + @Test - public void removeLines() throws FileNotFoundException{ + public void removeMultiplesLines() throws FileNotFoundException{ DataBase maDB=new DataBase(); - maDB.removeLines(0); + int res= maDB.removeMultiplesLines(2017004); + System.out.print(res); + } + @Test + public void removeLine() throws FileNotFoundException{ + DataBase maDB=new DataBase(); + int res= maDB.removeLine(2017014); + System.out.print(res); } @Test -- 2.49.1 From 13349f149b0004b8207981b2369645723bf398f0 Mon Sep 17 00:00:00 2001 From: NicolasFabregas Date: Thu, 28 Jan 2021 15:10:47 +0100 Subject: [PATCH 17/31] enleve des trucs inutiles et edit des commentaires --- .idea/misc.xml | 4 + src/main/java/fr/myny/database/DataBase.java | 78 ++++++++------------ 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 7193838..773f5e1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,9 @@ + +