Ajout éléments SQLite avec jsp
Bonjour
je rencontre un petit problème pour ajouter des éléments dans ma base SQLite à l'aide de jsp: Boutique.db (ProduitId, Marque, Gamme, Prix, Date, Description)
Pour commencer, j'ai un problème avec la conversion de la date récupérée:
je récupère une date sous forme chaine avec :
String dateString = new String(request.getParameter("date")) ;
Ensuite je formate la date
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy") ;
Et je récupère dans une variable la transformation
dat = sdf.parse(dateString) ;
Citation:
org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP:
Une erreur s'est produite à la ligne: 25 dans le fichier jsp: /AjoutProduit.jsp
SimpleDateFormat cannot be resolved to a type
22: String gam = new String(request.getParameter("gamme")) ;
23: Integer px = new Integer(request.getParameter("prix")).intValue() ;
24: String dateString = new String(request.getParameter("date")) ;
25: SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy") ;
26: dat = sdf.parse(dateString) ;
27:
28: String desc = new String(request.getParameter("description")) ;
Mon fichier : NouveauProduit.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import = "java.sql.*" %>
<%@ page import = "java.util.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ajout de produit dans la table</title>
</head>
<body>
<h3>Demande d'ajout d'un nouveau produit</h3>
<form method="get" action="AjoutProduit.jsp">
<p> Produit : <input type="text" name="produit" size="30"></p>
<p>Marque : <input type="text" name="marque" size="30"></p>
<p>Gamme : <input type="text" name="gamme" size="30"></p>
<p>Prix : <input type="text" name="prix" size="8"></p>
<p>Date : <input type="text" name="date" size="10"></p>
<p>Description : <input type="text" name="description" size="60"></p>
<input type="submit" value="OK">
</form>
</body>
</html> |
Mon fichier : AjoutProduit.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import ="java.sql.*" %>
<%@ page import ="java.util.*" %>
<% Class.forName("org.sqlite.JDBC") ; %>
<% Connection con = DriverManager.getConnection("jdbc:sqlite:Boutique.db") ; %>
<% Statement stmt = con.createStatement() ; %>
<% ResultSet result = null ; %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Requete</title>
</head>
<body>
<H2>Ajout d'un produit</H2>
<%
String prod = request.getParameter("produit") ;
String marq = new String(request.getParameter("marque")) ;
String gam = new String(request.getParameter("gamme")) ;
Integer px = new Integer(request.getParameter("prix")).intValue() ;
String dateString = new String(request.getParameter("date")) ;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy") ;
dat = sdf.parse(dateString) ;
String desc = new String(request.getParameter("description")) ;
%>
<% String requet = "INSERT INTO main.Produit VALUES('"+prod+"', '"+marq+"', '"+gam+"', '"+px+"', '"+dat+"', '"+desc+"')" ; %>
<% stmt.executeUpdate(requet) ; %>
<h3>Nouveau contenu :</h3>
<table border =1>
<tr>
<td><center><b>Produit</b></center></td>
<td><center><b>Marque</b></center></td>
<td><center><b>Gamme</b></center></td>
<td><center><b>Prix</b></center></td>
<td><center><b>Date</b></center></td>
<td><center><b>Description</b></center></td>
</tr>
<% result = stmt.executeQuery("SELECT * FROM Produit") ; %>
<% while (result.next()) { %>
<tr>
<td><% result.getString("ProduitId") ; %> </td>
<td><% result.getString("Marque") ; %> </td>
<td><% result.getString("Gamme") ; %> </td>
<td><% result.getString("Prix") ; %> </td>
<td><% result.getString("Date") ; %> </td>
<td><% result.getString("Description") ; %> </td>
</table>
</body>
</html>
<%
Statement.close() ;
con.close() ;
%> |