What is the best way to make a call to a stored procedure using JDBC if you only want to set some parameters?
If I just used SQL, I could set the parameters in the SQL name in SQL to call sproc. For instance. if I have a stored procedure with nine parameters, and I wanted to set parameters 1,2 and 9, leaving the rest to their default values, I can run this SQL:
exec my_stored_procedure @parameter_1 = "ONE", @parameter_2 = "TWO", @parameter_9 = "NINE"
Using JDBC (in particular, jConnect 6.0), it seems that when using CallableStatement you need to set the parameters by their integer index, and not by name. If I try to create a CallableStatement for the above stored procedure, with 9 parameters and only set parameters 1,2 and 9, for example:
myStoredProcedureCall = sybConn.prepareCall("{call my_stored_procedure (?, ?, ?, ?, ?, ? , ?, ?, ?)}"); myStoredProcedureCall.setString(1, "ONE"); myStoredProcedureCall.setString(2, "TWO"); myStoredProcedureCall.setString(9, "NINE"); ResultSet paramResults = myStoredProcedureCall.executeQuery();
Then I get this SQLException thrown:
*** SQLException caught *** SQLState: JZ0SA Message: JZ0SA: Prepared Statement: Input parameter not set, index: 2. Vendor: 0
For some background that I am trying to do, I need to create a process that receives product information from the IBM MQ thread and then creates the product in a third application. A third-party application uses Sybase to store data, and to create a product I need to call a stored procedure containing about 130 parameters. For the type of product I need to create, I need to install only about 15 of these parameters, the rest will remain by default.
The options I reviewed are as follows:
- Creating a custom stored procedure that sets only those values ββthat I need and then calls a third-party sproc product.
- Setting default values ββfor all parameters in Java.
Could there really be an easier way to do this?