insertion des données vers une base de donnée oracle à partir d'une page jsf
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:
viewId:/welcomeJSF.jsp - La vue /welcomeJSF.jsp na pas pu être restaurée.
voici mon bean:
-----------------------------------------------
Code:
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
| /*
* 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;
String s=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
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println ("driver etablie");
}
catch(Exception e)
{
System.out.println ("erreur:Driver int" +
"rouvable");
}
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 String insert() throws SQLException{
String resultat="";
Statement st = con.createStatement();
int val = 0;
try {
val = st.executeUpdate("insert into user_details values('"+ username +"','" + jobposition + "')");
} catch (SQLException ex) {
Logger.getLogger(InsertAction.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(val);
return resultat;
}
/** Creates a new instance of InsertAction */
public InsertAction(){
}
public static void main (String args[]) throws SQLException{
InsertAction B= new InsertAction ();
B.connexionBD();
B.insert();
}
} |
-----------------------------------------
ma page jsf
Code:
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
| <%@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>
<body>
<h:form>
<BODY BGCOLOR= "#FFDEAD" link="#00CED1" > <br/>
<table>
<tr height="50">
<td width="190"> username </td><td> <h:inputText value="#{InsertAction.username}" size="10" /> </td> <td>             jobposition </td><td> <h:inputText value="#{InsertAction.jobposition}" size="10" /></td></tr>
</table>
<h:commandButton id="submit" value="envoyer " style="width: 175px" action="#{InsertAction.insert}" ></h:commandButton>
</h:form>
</body>
</html>
</f:view> |
-------------------------------------------------------------
le problème réside au niveau de la page " welcomeJSF.jsp"
Pourriez-vous m'indiquer ce que je dois ajouter exactement dans ma page jsp
je vous remercie