Results 1 to 3 of 3
  1. #1
    haykel9 is offline Member
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Angry problem d'insertion

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!--
    Design by Free CSS Templates
    Download free CSS templates - Free CSS Templates
    Released for free under a Creative Commons Attribution 2.5 License


    -->
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Accueil</title>
    <link href="style/republic/style.css" rel="stylesheet" type="text/css" media="screen" />
    <style type="text/css">
    <!--
    body,td,th {
    color: #F63;
    }
    .Style1 {
    font-size: 36px;
    color: #0066FF;
    }
    -->
    </style></head>
    <body>
    <div id="wrapper">
    <div id="header">
    <div id="logo">
    <h1><a href="#">Media Bureautique </a></h1>
    <p> Vente et Entretien Materiel Bureautique Et Informatique <a href=></a></p>
    </div>
    </div>


    <!-- end #header -->
    <div id="menu">
    <ul>
    <li class="current_page_item"></li>
    <li></li>
    <li></li>

    <li></li>
    </ul>
    </div>
    <!-- end #menu -->
    <div id="page">
    <div id="page-bgtop">
    <div id="page-bgbtm">
    <div id="content">
    <div class="post">
    <h2 class="title"><a href="#"><marquee> Bienvenue sur le GPI de Media Bureautique</marquee></a></h2>
    <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
    <!--DWLayoutTable-->
    <tr>
    <td height="257" align="center" valign="middle">
    <p>&nbsp;</p>
    <%
    String Mat = request.getParameter("Mat");
    String Nom = request.getParameter("Nom");
    String Prenom = request.getParameter("Prenom");
    String Adresse = request.getParameter("Adresse");
    String Telephone= request.getParameter("Telephone");
    String Fax = request.getParameter("Fax");
    String Mail = request.getParameter("Mail");
    String login= request.getParameter("login");
    String password= request.getParameter("password");


    PreparedStatement pstatement = null;




    Connection myconn =null;
    Statement stmt =null;
    ResultSet RS=null;
    session.setAttribute("conn", myconn);
    session.setAttribute("stmt", stmt);
    try{
    Class.forName("com.mysql.jdbc.Driver");

    myconn = DriverManager.getConnection("jdbc:mysql://localhost:3306/gpimd", "root", "root");


    stmt = myconn.createStatement();
    }
    catch(ClassNotFoundException e){
    out.print("erreur driver");
    }
    int updateQuery = 0;

    // check if the text box is empty
    if(Mat!=null && Nom!=null && Prenom!=null&&Adresse!=null&&Telephone!=null&& Fax !=null&& Mail!=null && login!=null&& password!=null)
    {
    // check if the text box having only blank spaces
    if(Mat!="" && Nom!="" && Prenom!=""&&Adresse!=""&&Telephone!=""&& Fax !=""&& Mail!="" && login!=""&& password!=null) {
    try {

    // sql query to insert values in the secified table.
    String queryString = "insert into client (IDCLIENT,LOGIN,MOT_DE_PASSE,nom,prenom,tel,adress e,fax,mail) VALUES (?,?,?,?,?,?,?,?,?)";
    /* createStatement() is used for create statement
    object that is used for
    sending sql statements to the specified database. */
    pstatement = myconn.prepareStatement(queryString);
    pstatement.setString(1, Mat);
    pstatement.setString(2, login);
    pstatement.setString(3,password);
    pstatement.setString(4,Nom);
    pstatement.setString(5,Prenom);
    pstatement.setString(6,Adresse);
    pstatement.setString(7,Telephone);
    pstatement.setString(8,Fax);
    pstatement.setString(9,Mail);
    updateQuery = pstatement.executeUpdate();
    if (updateQuery != 0) { %>
    <br>
    <TABLE style="background-color: #E3E4FA;"
    WIDTH="54%" border="1">
    <tr><th>l'ajout est valide.</table>

    <%
    }
    }
    catch (Exception ex) {
    out.println("Erreur");

    }
    finally {
    // close all the connections.
    pstatement.close();
    myconn.close();
    }
    }
    }
    else
    {%>
    <table> <tr> chon vide </tr></table>
    <% }
    %>
    <!-- end #footer -->
    </body>
    </html>

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    And your question is?

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    1.You should not write database/business logic in jsp.

    2.You have used statement object but not used anywhere

    3.why are you storing null connection/statement in session?

    4. what error you are getting when you are doing insertion?

    5.Have you checked the table column names?
    Ramya:cool:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •