-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManager.java
80 lines (65 loc) · 2.09 KB
/
Manager.java
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
package competition;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class Manager {
private Connection connection;
// constructeur
public Manager() {
// pour arriver à se co : https://www.commentcamarche.net/forum/affich-18633582-echec-de-la-connexion-tcp-ip-a-l-hote-guettaf
String url = "jdbc:sqlserver://DESKTOP-BL48RPL\\TEST_SQL:1433;databaseName=competition;integratedSecurity=true;";
String user = "MicrosoftAccount\\\\aitalvivem@gmail.com";
String pass = "Violent-Femme27";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection connection = DriverManager.getConnection(url, user, pass);
this.setConnection(connection);
System.out.println("Je suis connecté à la bdd\n");
}
catch(SQLException | ClassNotFoundException e){
e.printStackTrace();
}
}
// public void creeCompet(Competition compet)
// destructeur
public void destruct() {
try {
this.connection.close();
System.out.println("\nconnection terminée.");
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
public String[] getListCriteres() {
String req = "SELECT libCritere, importance FROM critere";
ArrayList<String> listeIntermediaire = new ArrayList<String>();
String[] listCriteres = null;
try {
PreparedStatement st = this.connection().prepareStatement(req);
ResultSet rs = st.executeQuery();
while(rs.next()) {
String str = rs.getString("libCritere")+" ( /"+rs.getInt("importance")+")";
listeIntermediaire.add(str);
}
listCriteres = new String[listeIntermediaire.size()] ;
listeIntermediaire.toArray(listCriteres);
st.close();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
return listCriteres;
}
// mutateur
public void setConnection(Connection co) {
this.connection = co;
}
// accesseur
public Connection connection() {
return this.connection;
}
}