SERVLET - ORACLE - NETWARE
Hello everybody,
Sorry for my english but i'm french.
I try to make a servlet with a post method in which a request to the database is made.
Here are the servlet, the html and the error returned :
SERVLET
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import java.math.*;
public class ServletLivreDOr extends HttpServlet {
private Statement instruction = null;
private Connection connexion = null;
public void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException{
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()) ;
connexion = DriverManager.getConnection ("jdbc:oracle:thin:@172.16.0.4:1521:ORCL","scott","tiger") ;
}
catch ( Exception e ) {
e.printStackTrace();
connexion = null;
}
String nom, description, prix, numCons;
nom = req.getParameter( "Nom" );
description = req.getParameter( "Description" );
prix = req.getParameter( "Prix" );
numCons = req.getParameter( "Num?ro d'identification" );
PrintWriter sortie = res.getWriter();
res.setContentType( "text/html" );
StringBuffer tamp = new StringBuffer() ;
if ( numCons.equals( "" ) || nom.equals( "" ) || prix.equals( "" ) ) {
tamp.append( "<H3> Veuillez cliquer sur le bouton Pr?c?dent et remplir tous les champs.</H3>" );
sortie.println( tamp.toString() ) ;
sortie.close();
return;
}
String ch = "'" + numCons + "','" + nom + "','" + description + "','" + prix + "'" ;
boolean succes = insererDansBD(ch);
if ( succes )
tamp.append( "<H2>Donn?e enregistr?e dans la base.</H2>" );
else
tamp.append( "<H2>Une erreur s'est produite. " +
"Veuillez r?essayer plus tard.</H2>" );
sortie.println( tamp.toString() ) ;
sortie.close();
try {
connexion.close();
}
catch( Exception e ) {
System.err.println( "Probl?me ? la fermeture de la base de donn?es" );
}
}
private boolean insererDansBD( String chaineAInserer ){
try {
instruction = connexion.createStatement();
instruction.execute("insert into consommables values (" + chaineAInserer + ");" );
instruction.close();
}
catch ( Exception e ) {
System.err.println( "Probl?me ? l?ajout d?un consommable" );
e.printStackTrace();
return false;
}
return true;
}
}
HTML
--
<HTML>
<HEAD>
<TITLE>Saisie de consommables</TITLE>
</HEAD>
<BODY>
<H1>Ajout de consommables</H1>
<FORM
ACTION="http://172.16.0.4:80/servlet/ServletLivreDOr"
METHOD="POST">
<PRE>
* Num?ro d'identification: <INPUT TYPE=text NAME="Num?ro d'identification">
* Nom: <INPUT TYPE=text NAME="Nom">
Description:<INPUT TYPE=text NAME="Description">
* Prix:<INPUT TYPE=text NAME="Prix"> F
Les champs marqu?s * sont obligatoires.
</PRE>
<INPUT TYPE=SUBMIT Value="Valider">
</FORM>
</BODY>
</HTML>
ERROR
Probleme a l'ajout d'un consommable
java.sql.SQLException: ORA-00911: invalid character
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:661
)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.jav
a:780)
at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(OracleStatement
.java:822)
at oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement.java:116
4)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStateme
nt.java:1210)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1448)
at ServletLivreDOr.insererDansBD(ServletLivreDOr.java:63)
at ServletLivreDOr.doPost(ServletLivreDOr.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:521)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
at com.novell.application.ServletGateway.ServletGateConnection.runServle
t(ServletGateConnection.java)
at com.novell.application.ServletGateway.ServletGateConnection.handleReq
uest(ServletGateConnection.java)
at com.novell.application.ServletGateway.ServletGateConnection.run(Servl
etGateConnection.java)
at java.lang.Thread.run(Thread.java:466)
Thank you for your help.

