Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
daniele licitra
Ranch Hand
Posts: 81
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all.

I've an Entity:


and a named query:



Within a controller, i do the query


I fill an array and call the method:



When i exec the query, this exception was thrown:

javax.persistence.PersistenceException: Exception thrown when executing query
at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:433)
at org.datanucleus.api.jpa.JPAQuery.getResultList(JPAQuery.java:211)
at com.bss.easycooking.libdataeasycooking.controller.ArticoliJpaController.findArticoliByCatMer(ArticoliJpaController.java:49)
...
Caused by: java.sql.SQLException: No value specified for parameter 1
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.checkAllParametersSet(PreparedStatement.java:2611)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2586)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2510)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2259)
...

It say that the parameter was not set...why? I forget something? thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what version of JPA you are using? Setting parameters for "in" wasn't supported until JPA 2.0.
 
daniele licitra
Ranch Hand
Posts: 81
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne, thanks for reply.



I use 2.1.0, in fact in the entity i can use javax.persistence.Index notation
 
daniele licitra
Ranch Hand
Posts: 81
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Workaround:


Instead of using a named query, i write the query inside the method and set the parameters with a MessageFormat. It's less efficient but it works.

There is a way to fix the use of named query?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic