Bonjour,
j'essai de faire un INSERT INTO :
lorsque j'exécute ce code :
j'ai l'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 private static final String SQL_INSERT = "INSERT INTO categorie (nom_categorie) VALUES ('?')"; @Override public void creer(Categorie categorie) throws DAOException { // TODO Auto-generated method stub Connection connexion = null; PreparedStatement preparedStatement = null; ResultSet valeursAutoGenerees = null; try { System.out.println("connection et ajout de la catégorie"); /* Récupération d'une connexion depuis la Factory */ connexion = daoFactory.getConnection(); preparedStatement = initialisationRequetePreparee( connexion, SQL_INSERT, true, categorie.getNom_categorie() ); int statut = preparedStatement.executeUpdate(); /* Analyse du statut retourné par la requête d'insertion */ if ( statut == 0 ) { throw new DAOException( "Échec de la création de la categorie, aucune ligne ajoutée dans la table." ); } /* Récupération de l'id auto-généré par la requête d'insertion */ valeursAutoGenerees = preparedStatement.getGeneratedKeys(); if ( valeursAutoGenerees.next() ) { /* Puis initialisation de la propriété id du bean categorie avec sa valeur */ categorie.setId_categorie( valeursAutoGenerees.getInt("id_categorie") ); } else { throw new DAOException( "Échec de la création de la categorie en base, aucun ID auto-généré retourné." ); } } catch ( SQLException e ) { System.out.println("erreur"+e.getMessage()); throw new DAOException( e ); } finally { fermeturesSilencieuses( valeursAutoGenerees, preparedStatement, connexion ); } }
Pourriez vous m'aider ? merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 connection et ajout de la catégorie erreurParameter index out of range (1 > number of parameters, which is 0). fr.xxx.dao.DAOException: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at fr.xxx.dao.CategorieDaoImpl.creer(CategorieDaoImpl.java:50) at fr.xxx.form.CategorieForm.ajouterCategorie(CategorieForm.java:42) at fr.xxx.servlet.Ajouter_categorie.doPost(Ajouter_categorie.java:52) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920) at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3813) at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3795) at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3840) at com.mysql.jdbc.PreparedStatement.setNull(PreparedStatement.java:3880) at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:4041) at fr.xxx.dao.DAOUtilitaire.initialisationRequetePreparee(DAOUtilitaire.java:73) at fr.xxx.dao.CategorieDaoImpl.creer(CategorieDaoImpl.java:34) ... 20 more
Partager