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
| import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import métier.Personne;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import actionForm.PersonneActionForm;
import com.mysql.jdbc.Statement;
public class PersonneAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PersonneActionForm personne = (PersonneActionForm) form;
/**
* if(personne.getNom() != null && personne.getPrenom()!= null &&
* personne.getAdresse() && !personne.getNom().equals("") &&
* !personne.getPrenom().equals("")&& !personne.getAdresse().equals(""))
*/
Personne perso = new Personne();
perso.setNom(personne.getNom());
perso.setPrenom(personne.getPrenom());
perso.setAdresse(personne.getAdresse());
// modification de données dans la base
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connexion = DriverManager.getConnection(
"jdbc:mysql://localhost/hamidou", "root", "drame");
Statement instruction = (Statement) connexion.createStatement();
instruction.executeUpdate("UPDATE PERSONNES SET nom='titi' "
+ " WHERE prenom='toto'");
} catch (ClassNotFoundException ex) {
System.err.print("Erreur Driver");
} catch (SQLException ex) {
System.err.print("Erreur localisation BD");
}
request.getSession(false).setAttribute("Personne", perso);
}
} |
Partager