IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JSF Java Discussion :

Insertion base de données


Sujet :

JSF Java

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2015
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Insertion base de données
    Bonjour,

    Svp est-ce que qq peut m'aider ?

    J'arrive plus à insérer les données de mon formulaire dans ma base de donnée Par contre j'ai pu me connecter à la base et y insérer des valeurs quelconques par le même code mais non pas à partir du formulaire. J'ai essayé tout mais vainement ((


    Voici mon code XHTML:

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    To change this license header, choose License Headers in Project Properties.
    To change this template file, choose Tools | Templates
    and open the template in the editor.
    -->
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
    <title>Flower Shop</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
    <link href="ressources/css/style.css" rel="stylesheet" type="text/css" />
    <link href="ressources/css/lightbox.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
    <div id="wrap">
    <div class="header">
    <div class="logo"><a href="http://all-free-download.com/free-website-templates/">
    <h:graphicImage url="ressources/images/electroni.jpg" alt="Duke waving" />
    </a></div>
    <div id="menu">
    <ul>
    <li><a href="http://all-free-download.com/free-website-templates/">home</a></li>
    <li><a href="about.xhtml">about us</a></li>
    <li><a href="category.xhtml">flowers</a></li>
    <li><a href="specials.xhtml">specials gifts</a></li>
    <li><a href="myaccount.xhtml">my accout</a></li>
    <li class="selected"><a href="register.xhtml">register</a></li>
    <li><a href="details.xhtml">prices</a></li>
    <li><a href="contact.xhtml">contact</a></li>
    </ul>
    </div>
    </div>
    <div class="center_content">
    <div class="left_content">
    <div class="title"><span class="title_icon">
    <h:graphicImage url="ressources/images/bullet1.gif" alt="Duke waving" />
    </span>Register</div>
    <div class="feat_prod_box_details">
    <p class="details"> Just register to bid on auctions.. </p>
    <div class="contact_form">
    <div class="form_subtitle">create new account</div>
    <h:form>
    <div class="form_row">

    </div>
    <div class="form_row">
    <label class="contact"><strong>Username:</strong></label>
    <h:inputText class="contact_input" id="username" value="#{login.username}" required="true" />
    </div>
    <div class="form_row">
    <label class="contact"><strong>Password:</strong></label>
    <h:inputSecret class="contact_input" id="password" value="#{login.password}" required="true" />
    </div>
    <div class="form_row">
    <label class="contact"><strong>Email:</strong></label>
    <h:inputText class="contact_input" id="email" value="#{login.email}" required="true" />

    </div>
    <div class="form_row">
    <label class="contact"><strong>Phone:</strong></label>
    <h:inputText class="contact_input" id="phone" value="#{login.phone}" required="true" />
    </div>
    <div class="form_row">
    <label class="contact"><strong>Company:</strong></label>
    <h:inputText class="contact_input" id="company" value="#{login.company}" required="true" />
    </div>
    <div class="form_row">
    <label class="contact"><strong>Adress:</strong></label>
    <h:inputText class="contact_input" id="adress" value="#{login.adress}" required="true" />
    </div>

    <div class="form_row">
    <div class="terms">
    <input type="checkbox" name="terms" />
    I agree to the <a href="http://all-free-download.com/free-website-templates/">terms &amp; conditions</a> </div>
    </div>
    <div class="form_row">
    <h:commandButton value="register" type="submit"
    action="#{login.signUp()}" />

    </div>
    </h:form>
    </div>
    </div>
    <div class="clear"></div>
    </div>
    <!--end of left content-->
    <div class="right_content">
    <div class="languages_box"> <span class="red">Languages:</span> <a href="http://all-free-download.com/free-website-templates/"></a> </div>
    <div class="currency"> <span class="red">Currency: </span> <a href="http://all-free-download.com/free-website-templates/">GBP</a> <a href="http://all-free-download.com/free-website-templates/">EUR</a> <a href="http://all-free-download.com/free-website-templates/"><strong>USD</strong></a> </div>
    <div class="cart">
    <div class="title"><span class="title_icon"><img src="images/cart.gif" alt="" /></span>My cart</div>
    <div class="home_cart_content"> 3 x items | <span class="red">TOTAL: 100$</span> </div>
    <a href="http://all-free-download.com/free-website-templates/" class="view_cart">view cart</a> </div>
    <div class="title"><span class="title_icon"><img src="images/bullet3.gif" alt="" /></span>About Our Shop</div>
    <div class="about">
    <h:graphicImage url="ressources/images/enchere.jpg" alt="Duke waving" /><p> Visit uBid.com for online auctions and get your bid on! Find great computer auctions, jewelry auctions, sports memorabilia auctions, cell phone auctions and more.. </p>
    </div>
    <a href="http://all-free-download.com/free-website-templates/">about us</a> <a href="http://all-free-download.com/free-website-templates/">services</a> <a href="http://all-free-download.com/free-website-templates/">privacy policy</a> <a href="http://all-free-download.com/free-website-templates/">contact us</a> </div>
    </div>
    </div>
    </h:body>
    </html>



    et là mon managedbean :


    package bean_if;

    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.RequestScoped;
    import java.io.Serializable;

    import java.sql.*;
    import java.util.Calendar;

    /**
    *
    * @author guidoline
    */
    @ManagedBean
    @RequestScoped
    public class Test implements Serializable {
    private int id ;

    private String username ;
    private String password ;
    private String email ;
    private String phone;
    private String company ;
    private String adress ;

    public int getId() {
    return id;
    }

    public void setId(int id) {
    this.id = id;
    }

    public String getUsername() {
    return username;
    }

    public void setUsername(String username) {
    this.username = username;
    }

    public String getPassword() {
    return password;
    }

    public void setPassword(String password) {
    this.password = password;
    }

    public String getEmail() {
    return email;
    }

    public void setEmail(String email) {
    this.email = email;
    }

    public String getPhone() {
    return phone;
    }

    public void setPhone(String phone) {
    this.phone = phone;
    }

    public String getCompany() {
    return company;
    }

    public void setCompany(String company) {
    this.company = company;
    }

    public String getAdress() {
    return adress;
    }

    public void setAdress(String adress) {
    this.adress = adress;
    }

    /**
    * Creates a new instance of test
    */
    public Test() {
    }


    /**
    * A Java MySQL PreparedStatement INSERT example.
    * Demonstrates the use of a SQL INSERT statement against a


    public void signUp()
    {
    try
    {
    // create a mysql database connection
    String myDriver = "com.mysql.jdbc.Driver";
    String myUrl = "jdbc:mysql://localhost:3306/user";
    Class.forName(myDriver);
    // the mysql insert statement
    try (Connection conn = DriverManager.getConnection(myUrl, "root", "root")) {
    // the mysql insert statement
    String query = " insert into userr (id, Username, Password, Email, Phone, Company, Adress)"
    + " values (?, ?, ?, ?, ?,?,?)";

    // create the mysql insert preparedstatement
    PreparedStatement preparedStmt = conn.prepareStatement(query);
    preparedStmt.setInt (1, 9);
    preparedStmt.setString (2, username);
    preparedStmt.setString (3,password );
    preparedStmt.setString (4, email);
    preparedStmt.setString (5, phone);
    preparedStmt.setString (6, company);
    preparedStmt.setString (7, adress);

    // execute the preparedstatement
    preparedStmt.execute();
    }
    }
    catch (Exception e)
    {
    System.err.println("Got an exception!");
    System.err.println(e.getMessage());
    }
    }
    }


    mon id dans la base est de type entier, les autres sont tous des chaines de caractère

  2. #2
    Membre confirmé Avatar de freddou17
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2013
    Messages
    341
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2013
    Messages : 341
    Points : 566
    Points
    566
    Par défaut
    Slt,
    Ton managedBean c'est Test.java du coup, sauf erreur de ma part, je ne vois pas d'ou vient ta variable #{login

    ++
    "Aucun de nous ne sait ce que nous savons tous, ensemble."
    Lien vers mon appli Funcash n'hésitez pas à donner votre avis

Discussions similaires

  1. SQL server Insertion base de donnés
    Par benoit85 dans le forum ASP.NET
    Réponses: 6
    Dernier message: 16/04/2009, 14h21
  2. Insertion base de données
    Par nattyroot dans le forum Accès aux données
    Réponses: 1
    Dernier message: 01/10/2008, 19h52
  3. Problème d'insertion base de donnée Access
    Par hh4life dans le forum Windows Forms
    Réponses: 2
    Dernier message: 28/08/2007, 19h26
  4. [DBExpress] Formulaire d'insertion (Base de donnée)
    Par Nadd dans le forum C++Builder
    Réponses: 14
    Dernier message: 12/07/2007, 10h22
  5. insertion base de donnée
    Par eriz dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 20/04/2007, 00h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo