<h:head>
<title>Suppression du contenu de la Table MySQL</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="Vider la table" action="Delete"></h:commandButton>
</h:form>
</h:body>
</html>
- et voici la classe Delete.java appelée par l'attribut action de <h:commandButton> :
import java.sql.*;
public class Delete{
public static void main(String[] args) {
System.out.println
("Example for Deleting All Rows from a database Table!");
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");
try{
Statement st = con.createStatement();
String sql = "DELETE FROM employee";
int delete = st.executeUpdate(sql);
if(delete == 0){
System.out.println("All rows are completelly deleted!");
}
}
catch(SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
Mon problème est quand je clique sur le bouton : "Vider la table" dans la page index.xhtml rien ne se passe ! (la classe Delete.java) n'est pas appelée (exécutée)).
je demande si vous avez une solution pour mon problème ou toute autre solution qui permettra d'exécuter cette classe Java à partir du bouton de la vue jsf.