Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CallableStatement: using named parameters to specify only certain parameter values #553

Open
gordthompson opened this issue Nov 16, 2017 · 7 comments

Comments

@gordthompson
Copy link
Contributor

(ref: this Stack Overflow question)

Section 13.3.2 of the JDBC 4.2 specification says

Named parameters can be used to specify only the values that have no default value.

In CODE EXAMPLE 13-21, the procedure COMPLEX_PROC takes ten parameters, but only the first and fifth parameters, PARAM_1 and PARAM_5, are required.

CallableStatement cstmt = con.prepareCall("{CALL COMPLEX_PROC(?, ?)}";
cstmt.setString("PARAM_1", "Price");
cstmt.setFloat("PARAM_5", 150.25);

I just tried this with 6.3.4.jre8-preview.jar and I couldn't get it to work. It seemed that I had to provide a parameter placeholder for every possible parameter, ((?,?,?,?,?,?,?,?,?,?) in the above example), and I didn't see a way to specify DEFAULT for a parameter that I would have otherwise simply omitted.

In other words, it seems like named parameter support for CallableStatement in mssql-jdbc is currently limited to allowing us to specify the parameters in any order, but not to "pick and choose" the parameters we actually supply.

Have I missed something?

@ulvii
Copy link
Contributor

ulvii commented Nov 17, 2017

Hi @gordthompson ,
Thank you for creating the issue, I can confirm that this is a deficiency in the implementation. #547 is potentially related, we will address the issue once/when the PR is merged.

@JaapD
Copy link

JaapD commented Mar 8, 2021

@cheenamalhotra It looks like it is in progress for more than two years. Is there any progress?

@peterbae
Copy link
Contributor

peterbae commented Mar 9, 2021

Hi @JaapD, we haven't been able to work on this, the team will let you know when we have an update.

@praskutti
Copy link

Hi @JaapD , I actually created a custom library for this. I will post the code in my github soon.

@kliakos
Copy link

kliakos commented Nov 26, 2022

Any update on whether this will be addressed soon?

@lilgreenbird
Copy link
Contributor

hi @kliakos
Sorry to report that this issue is still in our backlog it didn't make it to the top of the list in triage.

@github-project-automation github-project-automation bot moved this to To be triaged in MSSQL JDBC Aug 28, 2024
@Jeffery-Wasty Jeffery-Wasty moved this from To be triaged to Backlog in MSSQL JDBC Aug 28, 2024
@jocstar
Copy link

jocstar commented Feb 19, 2025

As part of a large update we included migrating from JTDS to the MS JDBC driver but hit this problem in testing. This is a big issue for us so I have been looking into the possibility of providing a patch for it. I do have a proof of concept test working that will probably be suitable for our internal use but have a question before looking to take it any further publicly.

  1. According to the JDBC4.1 spec -
It is not possible to combine setting parameters with ordinals and with names in the same statement. 
If ordinals and names are used for parameters in the same statement, an SQLException is thrown

This rule doesn't currently seem to be enforced, and there is an existing unit test - StatementTest.testJdbc41CallableStatementMethods - that does mix parameters, so a little unsure what to do about that. My POC did enforce this but I took that out after seeing that test fail, so now in my experiment this test still passes, but it is not in keeping with the spec as far as I can see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

8 participants