Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting parameter in a CallableStatement

Status
Not open for further replies.

dharmer1975

Programmer
Apr 6, 2001
11
US
What's the difference between between these two statements--they appear to do the same thing, but the second one doesn't work:

CallableStatement cs = con2.prepareCall("{call harmerd.FERPmonthlybyregion (?, 'CL%')}");
cs.setString(1, "harmerd." + timeperiod);


CallableStatement cs = con2.prepareCall("{call harmerd.FERPmonthlybyregion (?,?)}");
cs.setString(1, "harmerd." + timeperiod);
cs.setString(2, "CL%");

------------------
I ideally want to do this to set the second parameter:

String region = (request.getParameter("Region"));
cs.setString(2, "region");

(region would have a string value of 'CL%'

Here's the error I get when using setString to set both paramters instead of hardcoding the second one:

SQLException caught: [Microsoft][ODBC SQL Server Driver][SQL Server]Unclosed quotation mark before the character string 'CL% '. [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'CL% '.


Can somebody please help me--I've been stuck for 2 days now :( Thanks,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top