Nico creation methodes vides #7
2 changed files with 122 additions and 12 deletions
|
|
@ -10,18 +10,14 @@ import com.opencsv.CSVReader;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DataBase {
|
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;
|
Connection conn;
|
||||||
/**
|
/**
|
||||||
* Le constructeur de DataBase
|
* Le constructeur de DataBase
|
||||||
*/
|
*/
|
||||||
public DataBase(){
|
public DataBase(){
|
||||||
/*try{getConnection();}
|
|
||||||
catch(SQLException sqle){
|
|
||||||
System.out.print(sqle);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -88,8 +84,7 @@ public class DataBase {
|
||||||
String line=sc.nextLine();
|
String line=sc.nextLine();
|
||||||
line="";
|
line="";
|
||||||
String date, jour, mois, an;
|
String date, jour, mois, an;
|
||||||
while (sc.hasNext()) //returns a boolean value
|
while (sc.hasNext()){
|
||||||
{
|
|
||||||
j=(i%25)+1;
|
j=(i%25)+1;
|
||||||
if(j==1) {
|
if(j==1) {
|
||||||
line=line+'(';
|
line=line+'(';
|
||||||
|
|
@ -167,7 +162,7 @@ public class DataBase {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(url);
|
conn = this.getConnection();
|
||||||
if(conn!=null) {
|
if(conn!=null) {
|
||||||
Statement stmt = conn.createStatement();
|
Statement stmt = conn.createStatement();
|
||||||
stmt.executeQuery(sql);
|
stmt.executeQuery(sql);
|
||||||
|
|
@ -314,9 +309,121 @@ public class DataBase {
|
||||||
/**
|
/**
|
||||||
* La methode de mise a jour de la base de donnees
|
* 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() {
|
public Connection getConnection() {
|
||||||
conn = null;
|
conn = null;
|
||||||
try {
|
try {
|
||||||
|
|
@ -332,6 +439,5 @@ public class DataBase {
|
||||||
System.out.println("on a des pb:" + e.getMessage());
|
System.out.println("on a des pb:" + e.getMessage());
|
||||||
}
|
}
|
||||||
return conn;
|
return conn;
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,11 @@ class DataBaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateDataBase() {
|
void updateDataBase() throws FileNotFoundException {
|
||||||
|
DataBase maDB=new DataBase();
|
||||||
|
Connection maCo=maDB.getConnection();
|
||||||
|
maDB.updateDataBase();
|
||||||
|
assertNotNull(maCo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Reference in a new issue