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!

Callable statement question -- what am I missing?

Status
Not open for further replies.

dharmer1975

Programmer
Apr 6, 2001
11
US
The following servlet code snipets calls a stored procedure in SQL Server:

----------------------------------------------------------
String timeperiod = (request.getParameter("StartMonth") + request.getParameter("StartYear"));
String region = (request.getParameter("Region")); // Value is CL%


THIS WORKS...

CallableStatement cs = con2.prepareCall("{call harmerd.FERPmonthlybyregion ('harmerd.jun00', 'CL%')}");
cs.executeQuery();

THIS DOESN'T...

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

--------------------------------------------------

For some reason I keep getting this error when I don't hardcode the parameter values in the callablestatement:

SQLException caught: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'harmerd'. [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared."


I realize this is somewhat messy, but it seems so simple that it's driving me nuts. Any help would be greatly appreciated. Thanks,

Dan

PS: Just in case, here's the procedure:

--------------------------------------------------
CREATE PROCEDURE FERPmonthlybyregion @selectedview Varchar (20), @region as Varchar (255)
as

declare @x as varchar(500)
set @x = 'select distinct((select cast(sum(Number_of_Responses)as float) from ' + @selectedview + ' where pool like "' + @region + '") / (select cast(count(distinct(imc_trackingnumber))as float) from ' + @selectedview + ' where pool like "' + @region + '")) as #_of_Responses_to_Resolution
from ' + @selectedview + ''

execute( @x )

------------------------------------------------
 
Maybe...

cs.setString(1, "'harmerd." + timeperiod + "'");
cs.setString(2, "'" + region + "'");
 
Nope :)

Still got the problem. This is driving me nuts... By the way, I'm just using the jdbc-odbc-bridge in case that matters. So who's the bad-to-the-bone programmer who can figure out what's wrong here? Thanks :cool:

-Dan
 

Try this..

timeperiod="harmerd." + timeperiod;
CallableStatement cs = con2.prepareCall("{call harmerd.FERPmonthlybyregion (?,?)}");
cs.setString(1, timeperiod);
cs.setString(2, region);
cs.executeQuery();
 
Make sure you use the same field order as what is in your select. I beleive they have to match. I had some code which calls store procedures on a SQL server and I had to make sure the order matched the Select.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top