Insertion jsp

MARWA -  
arth Messages postés 9374 Date d'inscription   Statut Contributeur Dernière intervention   -
Salut,
alors mon problème c'est: j'ai mon code jsp d'insertion de données
dans ma base de données mais quand j'exécute elle apparaît blanche.
svp aidez moi

voilà mon code jsp :
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ResultatPatient</title>
<style type="text/css">
<!--
.Style12 {color: #000000; }
.Style13 {font-size: 18px}
.Style2 {color: #FFFFFF}
body {
background-color: #ECF5FF;
}
-->
</style>
</head>
<body>
<p>
<%
String a =request.getParameter("cinp");
String b=request.getParameter("nomp");
String c=request.getParameter("prenomp");
String d=request.getParameter("daten");
int nb;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("JDBC:ODBC:cabinetmedecin");
Statement st=con.createStatement();
if (ch==1)
{
msg="Echec d'insertion ,verifier données";
ResultSet rs =st.executeQuery("Select * from patient " );
rs.next();
nb=st.executeUpdate("insert into patient values('"+a+"','"+b+"','"+c+"','"+d+"')");
if (nb!=0)

%>
Insertion avec succes !</p>
<table align="center" border="1" width="1038">
<tbody>
<tr>
<th scope="col" height="23" style="font-weight: normal;">N° carte
d'identitée</th>
<th scope="col" style="font-weight: normal;">Nom du patient</th>
<th style="font-weight: normal;" scope="col">Prenom du patient</th>
<th scope="col" style="font-weight: normal;">Date de naissance</th>
<th scope="col" style="font-weight: normal;">Action</th>
</tr>
<tr>
<th scope="col" height="26" width="130"> <%rs.getString("cinp");%></th>
<th scope="col" width="117"> <%rs.getString("nomp");%></th>
<th scope="col" width="124"> <%rs.getString("prenomp");%></th>
<th scope="col" width="130"> <%rs.getString("daten");%></th>
<th scope="col" width="349"><form id="form3" name="form3" method="post" action="supmod.jsp">
<big>
<input name="ch"
value="radiobutton" type="radio" />
<small>Suppression</small></big> <big>
<input name="ch"
value="radiobutton" type="radio" />
<small>Modification</small></big>
<input name="ok"
value="ok" type="submit" />
</form></th>
</tr>
</tbody>
</table>
</body>
</html>



merci d'avance

4 réponses

arth Messages postés 9374 Date d'inscription   Statut Contributeur Dernière intervention   1 293
 
C'est moi ou le try et le if ne sont pas fermés?
1
marwa
 
Une erreur s'est produite à la ligne: 30 dans le fichier jsp: /resultatpatient.jsp
ch cannot be resolved
27: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
28: Connection con=DriverManager.getConnection("JDBC:ODBC:cabinetmedecin");
29: Statement st=con.createStatement();
30: if (ch==1)
31: {
32: msg="Echec d'insertion ,verifier données";}
33: ResultSet rs =st.executeQuery("Select * from patient " );


Une erreur s'est produite à la ligne: 32 dans le fichier jsp: /resultatpatient.jsp
msg cannot be resolved
29: Statement st=con.createStatement();
30: if (ch==1)
31: {
32: msg="Echec d'insertion ,verifier données";}
33: ResultSet rs =st.executeQuery("Select * from patient " );
34: rs.next();
35: nb=st.executeUpdate("insert into patient values('"+a+"','"+b+"','"+c+"','"+d+"')");


An error occurred at line: 144 in the generated java file
Syntax error, insert "Finally" to complete TryStatement

An error occurred at line: 145 in the generated java file
Syntax error, insert "}" to complete ClassBody
0
marwa
 
je trouve cette erreur

Une erreur s'est produite à la ligne: 30 dans le fichier jsp: /resultatpatient.jsp
ch cannot be resolved
27: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
28: Connection con=DriverManager.getConnection("JDBC:ODBC:cabinetmedecin");
29: Statement st=con.createStatement();
30: if (ch==1)
31: {
32: msg="Echec d'insertion ,verifier données";}
33: ResultSet rs =st.executeQuery("Select * from patient " );


Une erreur s'est produite à la ligne: 32 dans le fichier jsp: /resultatpatient.jsp
msg cannot be resolved
29: Statement st=con.createStatement();
30: if (ch==1)
31: {
32: msg="Echec d'insertion ,verifier données";}
33: ResultSet rs =st.executeQuery("Select * from patient " );
34: rs.next();
35: nb=st.executeUpdate("insert into patient values('"+a+"','"+b+"','"+c+"','"+d+"')");


An error occurred at line: 144 in the generated java file
Syntax error, insert "Finally" to complete TryStatement

An error occurred at line: 145 in the generated java file
Syntax error, insert "}" to complete ClassBody
0
arth Messages postés 9374 Date d'inscription   Statut Contributeur Dernière intervention   1 293
 
Effectivement ch n'est déclaré nul part ? C'est quoi ch?
0
marwa
 
j'ai mm utilisée ce code pour l'insertion et sa fonctionne pas
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Patients</title>
</head>
<body>
<%
String a=request.getParameter("cinp");
String b=request.getParameter("nomp");
String c=request.getParameter("prenomp");
String d=request.getParameter("daten");
String sql="";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:mysql://localhost:3306/cabinetmedecin ";
Connection con=DriverManager.getConnection(url,"root","");
Statement s=con.createStatement();
sql="INSERT INTO patient(cinp,nomp,prenomp,daten)"+"VALUES"+"('"+a+"','"+b+"','"+c+"','"+d+"')";
s.executeUpdate(sql);
s.close();
con.close();
out.println("Patient ajouté avec succés");
}
catch(SQLException e){
}
%> insertion avec succes
<table align="center" border="1" width="1038">
<tbody>
<tr>
<th scope="col" height="23" style="font-weight: normal;">N° carte
d'identitée</th>
<th scope="col" style="font-weight: normal;">Nom du patient</th>
<th style="font-weight: normal;" scope="col">Prenom du patient</th>
<th scope="col" style="font-weight: normal;">Date de naissance</th>
<th scope="col" style="font-weight: normal;">Action</th>
</tr>
<tr>
<th scope="col" height="26" width="130"> <%rs.getString("cinp");%></th>
<th scope="col" width="117"> <%rs.getString("nomp");%></th>
<th scope="col" width="124"> <%rs.getString("prenomp");%></th>
<th scope="col" width="130"> <%rs.getString("daten");%></th>
<th scope="col" width="349"><form id="form3" name="form3" method="post" action="supmod.jsp">
<big>
<input name="ch"
value="radiobutton" type="radio" />
<small>Suppression</small></big> <big>
<input name="ch"
value="radiobutton" type="radio" />
<small>Modification</small></big>
<input name="ok"
value="ok" type="submit" />
</form></th>
</tr>
</tbody>
</table>
<br><br><br><br>
</body>
</html>
0
marwa
 
svp aidez moi
0
arth Messages postés 9374 Date d'inscription   Statut Contributeur Dernière intervention   1 293
 
Il faudrait rajouter une ligne dans le catch histoire d'afficher s'il y a une erreur.
0