JSP + JAVA problème insertion dans ma table postgresql
Bonjour,
J'ai un petit soucis pour réaliser des insertions dans une base de donnée (NB :Les insertions je n'ai aucun problème a réaliser les insert avec en JAVA mais en utilisant JSP je n'y arrive pas). Dans un premier temps j'ai réussi à récupérer les différentes infomrations. Je voudrai en insérer maintenant mais ma méthode ne fonctionne pas et je ne suis pas sur d'être sur la bonne voie.
Voici mes codes :
fichier 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
| <html>
<head><title>
insertion dans la base
</title></head>
<body>
<form method="POST">
reference : <input type=text name="refpro"><BR>
libelle : <input type=text name="libelle"><BR>
prix : <input type=text name="prix"><BR>
qstock : <input type=text name="qstock"><BR>
<input type="submit" value="insert"><BR>
</form>
</body>
<jsp:useBean id="jdbc" class="web.Lien"/>
<%
String refpro = request.getParameter("refpro");
String libelle = request.getParameter("libelle");
String prixint = request.getParameter("prix");
String qstockint =request.getParameter("qstock");
String insertion = jdbc.insertion("refpro","libelle","prix","qstock");
%>
</html> |
Code java
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
| package web;
import java.sql.*;
public class Lien{
private Connection connexion;
private Statement requète;
private boolean correct;
public Lien(){
try{
initierConnexion();
}catch(ClassNotFoundException e) {System.err.println("Erreur de chargement du pilote : " + e);}
catch(SQLException e) {System.err.println("Connexion impossible : " + e);}
catch(Exception e) {System.err.println("Erreur : " + e);}
}
private void initierConnexion() throws Exception{
Class.forName("org.postgresql.Driver");
connexion = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres","postgres","postgres");
System.out.println("ouverture de la connexion à la base");
requète = connexion.createStatement();
correct = true;
}
public boolean isCorrect(){
return correct;
}
public String insertion(String refpro,String libelle, double prix, int qstock){
if(!correct)
return null;
String sql ="insert into produit (refpro,libelle,prix,qstock) values ('"+refpro+"','"+libelle+"',"+prix+","+qstock+")";
ResultSet réponse = null;
String nom = null;
try{
réponse = requète.executeQuery(sql);
if(réponse.next())
nom = réponse.getString("qstock");
}catch (SQLException e) {System.err.println("Erreur SQL : " + e.getMessage());}
catch(Exception e) {System.err.println("Erreur : " + e);}
return nom;
}
public static void main (String []args){
Lien lientest = new Lien ();
lientest.insertion("NE555", "puce", 9.55 , 310);
}
} |
J'ai le message d'erreur suivant
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
| org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP:
Une erreur s'est produite à la ligne: 33 dans le fichier jsp: /test.jsp
The method insertion(String, String, double, int) in the type Lien is not applicable for the arguments (String, String, String, String)
30:
31:
32:
33: String insertion = jdbc.insertion("refpro","libelle","prix","qstock");
34:
35:
36:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:443)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:367)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:341)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) |
Comme exprimé avant, je ne sais pas si ma méthode correcte, de plus je dois réussir a transformer mes string en double et int mais je ne sais pas comment avec le jsp.
D'avance merci