Bonjour tous le monde,
Je suis entrain de créer l'application de mon projet de stage, et j'ai besoin de votre aide.
La premiere étape de mon projet, consiste a lire un fichier texte, et prendre les informations dedans, et les inserer dans une base de données.
je vous propose cette solution, mais je ne sais pas ou est le problem
Si vous avez d'autre suggestions, veuillez les proposer
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 package Test; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; public class TestConnexion { public static void main (String args[]){ String filePath = ".\\journal.txt"; String tkn; ArrayList<String> prs = new ArrayList(); BufferedReader buff = null; try { st = con.createStatement(); rs = st.executeQuery(strsql); buff = new BufferedReader(new FileReader(filePath)); try { String line; while ((line = buff.readLine()) != null) { StringTokenizer s = new StringTokenizer(line," "); if (line.startsWith("MATRICULE")){ int i=0, j=0, k; while (s.hasMoreTokens()) { k=i+i*j; j++; if (i==0) {i++; s.nextToken();} else if (i==1) { i++; s.nextToken();} else if (i==2){ i++; prs.add(s.nextToken()); System.out.println(prs.get(k)); } else if (i==3) { i++; prs.add(s.nextToken()); System.out.println(prs.get(k)); } else if (i==4) { i++; prs.add(s.nextToken()); System.out.println(prs.get(k)); } else if (i==5) { i++; tkn = s.nextToken(); if(tkn.length() != 0){ prs.add(tkn); System.out.println(prs.get(k)); } else prs.add(" "); } else if (i==6) { i++; tkn = s.nextToken(); if(tkn.length() != 0){ prs.add(tkn); System.out.println(prs.get(k)); } else prs.add(" "); } else if (i==7) { i++; tkn = s.nextToken(); if(tkn.length() != 0){ prs.add(tkn); System.out.println(prs.get(k)); } else prs.add(" "); } } } } } catch (IOException ex) { Logger.getLogger(TestConnexion.class.getName()).log(Level.SEVERE, null, ex); } finally { try { buff.close(); } catch (IOException ex) { Logger.getLogger(TestConnexion.class.getName()).log(Level.SEVERE, null, ex); } } } catch (FileNotFoundException ex) { Logger.getLogger(TestConnexion.class.getName()).log(Level.SEVERE, null, ex);} } } }
Merci d'avance
Partager