java.sql.SQLException: No value specified for parameter 2

Stack Overflow | Akshay Mehta | 4 months ago
  1. 0

    How to pass null value in stored procedure from Java?

    Stack Overflow | 4 months ago | Akshay Mehta
    java.sql.SQLException: No value specified for parameter 2
  2. 0

    Hibernate and Query with criteria No value specified for parameter 2

    Stack Overflow | 4 years ago | java_user
    org.hibernate.exception.SQLGrammarException: could not execute query
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    on startup, mismatch exception

    GitHub | 1 month ago | ProgrammerDan
    java.sql.SQLException: No value specified for parameter 2
  5. 0

    Specifying the maxResults parameter of a query results in a SQLException. Similiar queries using Hibernate Core work fine. Setting or ommiting the firstResult parameter doesn't influence that behaviour. I guess the code does only add a "limit ?" to the sql query but forgets to set the actual parameter or its setting it for the parameter with a wrong parameter index. I'm using the following query method: public List< ? > query(String queryString, Object[] parameters, int start, int max) throws DataAccessException { EntityManager em = emf.createEntityManager(); EntityTransaction tx = null; try { tx = em.getTransaction(); tx.begin(); Query qry = em.createQuery(queryString); qry.setFirstResult(start); qry.setMaxResults(max); for (int i = 0; i < parameters.length; i++) { qry.setParameter(i, parameters[i]); } List< ? > result = qry.getResultList(); tx.commit(); return result; } catch (RuntimeException e) { if (tx != null) tx.rollback(); throw new DataRetrievalFailureException("Querying failed", e); } finally { em.close(); } } This is the stack trace I get: org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2150) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026) at org.hibernate.loader.Loader.list(Loader.java:2021) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:296) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:992) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:38) at model.dao.ejb3.Ejb3DAO.query(Ejb3DAO.java:270) at model.services.contacts.ContactManager.getAllContacts(ContactManager.java:131) at richclient.UpdateIndexAction$1.run(UpdateIndexAction.java:89) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76) Caused by: java.sql.SQLException: No value specified for parameter 2 at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1250) at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1198) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:963) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137) at org.hibernate.loader.Loader.getResultSet(Loader.java:1676) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223) at org.hibernate.loader.Loader.doList(Loader.java:2147) ... 11 more

    Hibernate JIRA | 1 decade ago | Johan Steiner
    org.hibernate.exception.SQLGrammarException: could not execute query

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.sql.SQLException

      No value specified for parameter 2

      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException()
    2. com.mysql.cj
      CallableStatement.execute
      1. com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:695)
      2. com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:663)
      3. com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:653)
      4. com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:638)
      5. com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:606)
      6. com.mysql.cj.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2166)
      7. com.mysql.cj.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2146)
      8. com.mysql.cj.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2083)
      9. com.mysql.cj.jdbc.PreparedStatement.execute(PreparedStatement.java:1120)
      10. com.mysql.cj.jdbc.CallableStatement.execute(CallableStatement.java:790)
      10 frames
    3. org.hibernate.result
      OutputsImpl.<init>
      1. org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:51)
      1 frame