Originally posted by sri pat:
Actually I am executing a stored procedure(huge) with several parameters getting dynamically as part of the SQL. Do I need to change the stored procedure all the way(variables to ? marks) or is there anyway I can change the input parameters which I am passing dynamically.
Just to be clear, you don't need to change the stored procedure it self at all. It's only the String that you are giving to JDBC. Instead of building the SQL as it would look if you typed it into isql directly, you build a String with ?s where the parameters would be.
You can write (admittedly tricky and error-prone) Java code to build the query dynamically based on input parameters as you are now. After preparing the statement with the Connection, set the parameter values on it and execute it.
I just looked up the JavaDocs again and I was mistaken: you need to use
CallableStatement for both stored procedures and functions. The queries look like this:
My work machine appears to be down now, but if I can get to it tonight I'll post some code I wrote about nine months ago to call some stored procedures and functions. I do remember having to futz with the syntax a bit to get it to work.
[ December 22, 2004: Message edited by: David Harkness ]