Bonjour,
J'ai une classe "UserLogin" qui permet de faire l'authentification (login et passe) d'une entreprise, et j'ai besoin après l'authentification, de récupérer l'identifiant de cette entreprise dans une autre classe pour l'utiliser dans d'autres traitements, mais j'arrive plus à savoir comment . Comment faire pour pouvoir récupérer dans l'autre classe la variable id_entreprise, que j'ai extrait de la base de données lors de l'authentification?
Merci
Le bout de code de la classe UserLogin.Java, qui récupère l'identifiant de l'entreprise authentifiée
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 @Override public void actionPerformed(ActionEvent arg0) { String un=uname.getText(); String pa= new String(pass.getPassword()); System.out.println("le login saisi est: "+un); connectToDB(); try { // statement = connection.createStatement(); PreparedStatement statement = (PreparedStatement) connection.prepareStatement("select * from entreprise where login = (?)"); statement.setString(1,un); rs=(ResultSet)statement.executeQuery(); //rs = statement.executeQuery("Select * from entreprise where login like "+"'"+un+"'"); if (un==""){ ErreurVide = new JOptionPane(); ErreurVide.showMessageDialog(null, "Veuillez saisir vos paramètres", "Informations non saisies", JOptionPane.ERROR_MESSAGE);} else if (un!=""){ if (rs.next()){ id_entreprise = rs.getInt("id_entreprise"); Entreprise entrepacheteur = new Entreprise(); entrepacheteur.setId_entreprise(id_entreprise); // String nom_entreprise = rs.getString("nom_entr"); // String login = rs.getString("login"); passVerif = rs.getString("passe"); int row = rs.getRow(); System.out.println("Données contenues dans la ligne "+row); System.out.println("id entreprise : "+id_entreprise); if ((pa.equals(passVerif))){ dispose(); //new AgentCommercialAchat(); } else { ErreurPass = new JOptionPane(); ErreurPass.showMessageDialog(null, "Veuillez vérifier votre mot de passe", "Erreur", JOptionPane.ERROR_MESSAGE); } } else { ErreurLogin = new JOptionPane(); ErreurLogin.showMessageDialog(null, "Veuillez vérifier votre login", "Erreur", JOptionPane.ERROR_MESSAGE); } } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } });
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 public class Entreprise { private int id_entreprise; private String nom_entreprise; private String secteur; private int tel; private double nserie; private Date Date_creation; private double chiffre_affaire; private String email; private int fax; private String login; private String passe; public Entreprise(){ } public Entreprise(int id_entreprise){ this.id_entreprise=id_entreprise; } public int getId_entreprise() { return id_entreprise; } public void setId_entreprise(int id_entreprise) { this.id_entreprise = id_entreprise; } public String getNom_entreprise() { return nom_entreprise; } public void setNom_entreprise(String nom_entreprise) { this.nom_entreprise = nom_entreprise; } public String getSecteur() { return secteur; } public void setSecteur(String secteur) { this.secteur = secteur; } public int getTel() { return tel; } public void setTel(int tel) { this.tel = tel; } public double getNserie() { return nserie; } public void setNserie(double nserie) { this.nserie = nserie; } public Date getDate_creation() { return Date_creation; } public void setDate_creation(Date date_creation) { Date_creation = date_creation; } public double getChiffre_affaire() { return chiffre_affaire; } public void setChiffre_affaire(double chiffre_affaire) { this.chiffre_affaire = chiffre_affaire; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int getFax() { return fax; } public void setFax(int fax) { this.fax = fax; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPasse() { return passe; } public void setPasse(String passe) { this.passe = passe; } }
Partager