Bonjour,
J'en suis a l'etape ou je doit utilisé le service!
donc tout fonction jusque la!
voila ma classe
ContactData :
le main c'est pour tester si sa me renvoye bien les contact dans ma base
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 package test.gwt.server; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import test.gwt.client.util.Contact; public class ContactData { public static Contact[] getAllContacts() { String query = "Select nom, prenom, telephone, mail from contact"; Contact[] contacts = new Contact[9]; //9 c'est le nombre ligne de ma table! try { Connection conn; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/gwt", "root", "***"); Statement stmt = conn.createStatement(); ResultSet results = stmt.executeQuery(query); int i = 0; while(results.next()) { contacts[i]=new Contact(results.getString("nom"), results.getString("prenom"), results.getString("mail"), results.getString("telephone")); i++; } stmt.close(); conn.close(); } catch (SQLException e) { System.out.println("SQLException: " + e.getMessage()); System.out.println("SQLState: " + e.getSQLState()); System.out.println("VendorError: " + e.getErrorCode()); } return contacts; } public static void main(String[] args) { Contact[] c = ContactData.getAllContacts(); for(int i=0;i<c.length;i++) { System.out.println(c[i].getNom()+" "+c[i].getPrenom()+" "+c[i].getEmail()+" "+c[i].getTel()); } } }
donc le main marche mais quand je lance l'appli avec "monappli-shell.cmd"
hors quand dans ContactData je mets
et la ca marche aider moi!
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 package test.gwt.server; import test.gwt.client.util.Contact; public class ContactData { public static Contact[] getAllContacts() { Contact[] contacts = new Contact[]{ new Contact("Paul","Mc Cartney","@dvp.com","12"), new Contact("Ringo","Starr","@dvp.com","12"), new Contact("Yoko","Uno","@dvp.com","12"), new Contact("Bob","Dilan","@dvp.com","12"), new Contact("Ludwig","Von Beethoven","@dvp.com","12"), new Contact("Georges","Harrison","@dvp.com","12"), new Contact("Dick","Annegarn","@dvp.com","12"), new Contact("John","Lennon","@dvp.com","12")}; return contacts; } }
Partager