This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes SQLException: No parameter specified for parameter 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLException: No parameter specified for parameter 1" Watch "SQLException: No parameter specified for parameter 1" New topic
Author

SQLException: No parameter specified for parameter 1

Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi All
Consider the following code snippet:


Instead of "?" if I specify the value directly, I'm able to get the desired output. But when I use "?", I'm getting "SQLException: No parameter specified for parameter 1".

I have also tried using setEscapeProcessing(false), but still I get the same error.

Any way to get rid of this exception?


Thanks & Regards
Swapna Gouri
I "try", I "catch" and "finally" WIN !!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

You need to supply a value for the parameter using one of the set methods. How do you expect the value to be supplied if you don't set it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Sorry Bear ! I forgot to mention, the value will be passed from a JSP page through text fields.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

My answer still stands.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

String query = "Select Name from Users where ID = ? ";
pstmt = con.prepareStatement(query);

String id=<value retrieved from user request>

pstmt.setString(1,id);



Swastik
 
 
subject: SQLException: No parameter specified for parameter 1
 
Similar Threads
reusing the Statement object
how to escape ? in commons.dbutils.QueryRunner
'order by' clause in named query
Problem with Parameters in Hibernate query
java.sql.SQLException: Parameter missing IN or OUT index: 2