Insertion vers une base de donnée à partir d'une page jsf

Résolu
cs_enmaai Messages postés 22 Date d'inscription jeudi 16 décembre 2010 Statut Membre Dernière intervention 14 juin 2011 - 16 mai 2011 à 20:04
cs_enmaai Messages postés 22 Date d'inscription jeudi 16 décembre 2010 Statut Membre Dernière intervention 14 juin 2011 - 18 mai 2011 à 18:20
salut
voilà je veux faire l'ajout des données vers une base oracle à partir d'une page jsf
mais ça ne marche pas, quand j'introduis les données et je clique sur le bouton "envoyer" il s'affiche:

An Error Occurred:
javax.el.MethodNotFoundException: Method not found: InsertAction@1f6c1c1.insert()


voici le code:
ma page jsf:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>user</title>
</head>

<h:form>


username, <h:inputText value="#{InsertAction.username}" size="10" />,             job position, <h:inputText value="#{InsertAction.jobposition}" size="10" />

<h:commandButton id="submit" value="envoyer " style="width: 175px" action="#{InsertAction.insert}"></h:commandButton>


</h:form>

</html>
</f:view>
---------------------------------------------
voici mon bean:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import java.sql.Connection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.sql.*;
import java.sql.DriverManager;



/**
*
* @author utilisateur
*/
@ManagedBean(name="InsertAction")
@SessionScoped
public class InsertAction {

private String username;
private String jobposition;

Connection con = null;



public void setusername(String username){
this.username=username;
}
public void setjobposition(String jobposition){
this.jobposition=jobposition;
}

public String getusername()
{
return username;
}

public String getjobposition()
{
return jobposition;
}
public void connexionBD() {



try

{
String URL = "jdbc:oracle:thin:@localhost:1521:gmao";
String USER = "pfe";
String PASSWD = "gmao";

con =DriverManager.getConnection(URL,USER, PASSWD);
System.out.println ("connexion base pfe etablie");
}
catch(Exception e)
{
System.out.println ("erreur: base introuvable");

}}
public void insert(String requete) throws SQLException{

Statement st = con.createStatement();




int val = 0;
try {
val = st.executeUpdate("insert user_details values('" + username + "','" + jobposition + "')");
} catch (SQLException ex) {
Logger.getLogger(InsertAction.class.getName()).log(Level.SEVERE, null, ex);
}

System.out.println(val);
}

}
--------------------
le problème réside au niveau de la fonction insert() mais je ne sais pas comment la corriger
2) est-ce que je doit ajouter "commit" à la fin pour que l'insertion s'effectue réellement ç-à dire quand je consulte ma table oracle je peux trouver les données que j'ai insérées à partir de la page jsf
je vous remercie

8 réponses

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
18 mai 2011 à 16:02
C'est ta connexion, elle est nulle, ta méthode qui initialise la connexion doit être appellée dans le constructeur ou dans la méthode insert.

Met un point d'arret, les nullPointer sont faciles à voir.
3
Rejoignez-nous