aspose file tools*
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
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: 61437
    
  67

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: 61437
    
  67

My answer still stands.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SQLException: No parameter specified for parameter 1