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 & 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
Partager