question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CallableStatement: using named parameters to specify only certain parameter values

See original GitHub issue

(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?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ulviicommented, 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.

0reactions
lilgreenbirdcommented, Nov 28, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using named parameters in CALL statements in JDBC ... - IBM
To use named parameters with CALL statements, follow these steps: Invoke the Connection.prepareCall method with the CALL statement as its argument to create...
Read more >
Named parameters in a CallableStatement
You can use named parameters in a CallableStatement to identify the parameters by name instead of by ordinal position. This enhancement was introduced...
Read more >
Oracle, JBDC, CallableStatements and named parameters
In short: The names of the parameter do not refer to named placeholders in statement (like in JPA for example) but to PL/SQL...
Read more >
Call stored procedure specifying only parameters with a value
You have to use named parameters for this to work and you would have to assign a default value (which can be NULL)...
Read more >
Passing parameters to CallableStatement objects by name
You can use the CallableStatement interface to specify parameters by their names and not the previous method of specifying the parameter's index. You...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found