dharmer1975
Programmer
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 )
------------------------------------------------
----------------------------------------------------------
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 )
------------------------------------------------