Bonjour,
j"ai fait un programme qui fait l'ajout d'un message sachant que je dois récupérer le récepteur de la base de donné ,,j'ai fait tout mais il m'affiche cette erreur:
java.sql.SQLException: Incorrect integer value: 'sa' for column 'mat_etu' at row 1
Voici la servlet:
package Servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import metier.Message;
public class MsgPourEtudiant extends HttpServlet {
public void add(Message m){
try { Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/bdd","root","");
PreparedStatement pr=cn.prepareStatement("INSERT INTO message VALUES(NULL,?,?,?,?)");
pr.setString(1, m.getObjet());
pr.setString(2, m.getContenue());
pr.setString(3, m.getId_ens());
pr.setString(4, m.getMat_etu());
pr.execute();
}
catch (Exception ex) {
ex.printStackTrace(); } }
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
String objet=request.getParameter("objet");
String contenue=request.getParameter("contenue");
String id_ens=request.getParameter("id_ens");
String mat_etu=request.getParameter("mat_etu");
Message m= new Message(1, mat_etu, "0", objet, contenue);
add(m);
request.getSession().setAttribute("e", m);
request.getSession().setAttribute("rep3", "d'etude est ajoute avec succes ");
response.sendRedirect("Messagerie_enseignant.jsp");
}
}
et la jsp:
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
</head>
<body>
<div id="general">
<div id="entete">
<div id="logo">
<br/>
<marquee>
<h2> Bienvenue dans L'espace Numérique De Travail de l'UMMTO </h2>
</marquee>
</div>
<div id="menu-haut">
<span id="acc"> <a href="index.jsp"title=" Rotour a la page d'accueil"> Accueil </a></span>
<span id="ident"><a href="inscri.jsp" title="Inscrir si vous etez pas deja inscrire"> Inscription </a></span>
<span id="acce"> <a href="authen.jsp" title=" Identifiez-Vous"> Connexion</a></span>
<span id="ins"> <a href="cours.jsp" title=" cours à télécharger"> Cours </a></span>
<span id="cont"><a href="a propos.jsp" title=" plus d'information"> A propos </a></span>
</div>
</div>
<div id="navigation">
<div id="nav">
<ul>
<li>
<form id="search" name="search" action="chercher.php" method="POST">
<span id="g" >
<img src="css/en.png " align=center>
</span>
<p>
<input type="text" name="recherch" id="recherch" size="25" />
</p>
<p class="submit">
<button type="submit">Chercher</button>
</p>
</form>
</li> <li><a href="">Déconnexion</a></li>
<li><a href="Changer_Profile">Changer le profile</a></li>
<li><a href="Messagerie_enseignant.jsp">Messagerie</a></li>
<li><a href="UploadFiles.jsp">Gestion des cours</a></li>
<li><a href="">Gestion des notes</a></li>
<li><a href="">Gestion des affichages</a></li>
<li><a href="">Accéder aux CPs</a></li>
</ul>
</div>
</div>
<div id="principal">
<table border="0" width="">
<tr> <th width="80"></th>
<th colspan="10"><a href="NouveauMessageEns.jsp"title=" Rotour a la page d'accueil">Nouveaux messages</a><img src="css/envoyer_msg.png "> </th>
<th width="40"></th> <th ><a href="MessageRecuEns.jsp"title=" Rotour a la page d'accueil"> Message recus</a> <span id="g" >
<img src="css/msg_recus.png ">
</span></th>
<th width="40"></th> <th colspan="10"> <a href="MessageEnvoyeEns.jsp"title=" Rotour a la page d'accueil">Message envoyes</a><img src="css/msg_envoyes.png "> </th>
</tr></table>
<div id="ins-zone">
<form name="ins" id="ins" action="MsgPourEtudiant" method="POST" onSubmit="return verif()">
<fieldset class="zone1"><legend>Formulaire d'inscription</legend>
<p class="present">
<label for="mat_etu">Nom étudiant </label>
</p>
<p class="present">
<label for="nom_etu">objet</label>
</p>
<p class="present">
<label for="nom_etu">Message</label>
</p>
</fieldset>
<fieldset class="zone2">
<p>
<SELECT name="mat_etu" id="mat_etu" size=1>
<% Class.forName("com.mysql.jdbc.Driver");
Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/bdd","root","");
PreparedStatement pr = cn.prepareStatement("SELECT nom_etu FROM etudiant ");
ResultSet rs = pr.executeQuery();
while(rs.next()){
%>
<OPTION> <%=rs.getString("nom_etu")%><% }%> </OPTION>
</select>
</p>
<input name="objet" type="text" size="15" />
<p>
</p>
<p>
<textarea name="contenue" id="message" cols="30" rows="10"></textarea>
</p>
</fieldset>
<p class="submit">
<button type="submit" value="Valider">Envoyer</button>
<button type="reset">Annuler</button>
</p>
</form>
</div>
</div>
</div>
</body>
</html>
Pouvez vous m'aidez svp.Merci
Afficher la suite