Bonjour,

Pouvez vous m'aider, avec ce code, je n'ai aucune erreur, à l'exception des momments ou le nom et/ou le prénom contiennent une apostrophe.

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
 
public String GetClientPhone(Connection con, String nom, String prenom){
		String queryString = "select tel from client where nom='"+ nom +"' and prenom='"+ prenom +"'";
		String tel="---";
		try{
			stmt = con.createStatement();
			ResultSet rs = (ResultSet) stmt.executeQuery(queryString);
			while (rs.next()) {	
					tel=rs.getString("tel");
			}
			stmt.close();
		}
		// Close resources
		catch(SQLException ex) {
                        ...
		}
		return tel;
	}
Donc pour régler le problème, comme pour d'autres méthodes, j'utilise les prepared statement:
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
 
public String GetClientPhone(Connection con, String nom, String prenom){
		String queryString = "select tel from client where nom=? and prenom=?";
		String tel="---";
		try{
			PreparedStatement preparedStatement = con.prepareStatement(queryString);
			preparedStatement.setString(1,nom);
			preparedStatement.setString(2,prenom);
			ResultSet rs = (ResultSet)preparedStatement.executeQuery(queryString);		
			while (rs.next()) {	
					tel=rs.getString("tel");
			}
			preparedStatement.close();
		}
		// Close resources
		catch(SQLException ex) {
                        ...
		}
		return tel;
	}
Cependant, dans ce cas j'ai une erreur lors de "l'executeQuerry"...
Pourtant ce sont les meme données et j'utilise ce meme systeme pour obtenir dans info dans ma BD qui contiennent des apostrophes.

Quelqu'un a-t-il quelque chose pour m'aider?

Merci