Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL error Too few parameters
    primarykey
    data
    text
    <p>I'm having an sql problem. I writing a java application on top of a Access database. It's a search query for several fields and I know the error is in the part where I need to calculate the age of a person when he or she went missing. I'm returning a tablemodel in my method so i need to do the calculations in my query. My latest atempt to make it work is this:</p> <pre><code>public TableModel UpdateTable(String dossiernr, String naam, String voornaam, String startleeftijd, String eindleeftijd, String dossierjaar, String geslacht) { TableModel tb = null; String sql= "SELECT [Nr dossier],[Annee],[Nom],[Prenom],[Disparu le],[Ne le],[Sexe], DATEDIFF('yyyy',[Ne le],[Disparu le]) - iif(DATEADD('yyyy', DATEDIFF('yyyy',[Ne le],[Disparu le])," + "[Ne le])&gt;[Disparu le],1,0) AS Age FROM TotalTable " + "WHERE [Nr dossier] LIKE ? AND [Nom] LIKE ? AND [Prenom] LIKE ? AND [Annee] LIKE ? AND Age &gt;= ? AND Age &lt;= ? AND [Sexe] LIKE ?;"; try { PreparedStatement pstatement; Connection connection = PersistentieController.getInstance().getConnection(); pstatement = initStatement(connection,sql); pstatement.setString(1, "%" + dossiernr + "%"); pstatement.setString(2, "%" + naam + "%"); pstatement.setString(3, "%" + voornaam + "%"); pstatement.setString(4, "%" + dossierjaar + "%"); pstatement.setString(5, startleeftijd); pstatement.setString(6, eindleeftijd); pstatement.setString(7, "%" + geslacht + "%"); rs=pstatement.executeQuery(); tb = DbUtils.resultSetToTableModel(rs); pstatement.close(); }//einde try catch (SQLException e) { e.printStackTrace(); } //einde catch return tb; } </code></pre> <p>When i run it, i get following error:</p> <blockquote> <p>java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 8.</p> </blockquote> <p>I only work with 7 parameters and don't get why he's asking for 8. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload