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

Use JDBI to execute basic SQL statements in JDBC samples #10014

Open
ericharmeling opened this issue Mar 18, 2021 · 2 comments
Open

Use JDBI to execute basic SQL statements in JDBC samples #10014

ericharmeling opened this issue Mar 18, 2021 · 2 comments
Assignees
Labels
C-doc-improvement no-issue-activity P-2 Normal priority; secondary task

Comments

@ericharmeling
Copy link
Contributor

ericharmeling commented Mar 18, 2021

Eric Harmeling (ericharmeling) commented:

@rafiss

Jira Issue: DOC-1032

@ericharmeling ericharmeling added A-sql P-2 Normal priority; secondary task C-doc-improvement labels Mar 18, 2021
@ericharmeling ericharmeling self-assigned this Mar 18, 2021
@rafiss
Copy link
Contributor

rafiss commented Mar 18, 2021

See #9998 for where this thought came from:

with vanilla JDBC you need to do

PreparedStatement p = connection.prepareStatement("DELETE from promo_codes WHERE code IN(?, ?, ?)");
p.setString(1, codeOne);
p.setString(2, codeTwo);
p.setString(3, codeThree);
p.executeUpdate(); 

The placeholder arguments are important. Using normal string concatenation leaves the code open to SQL injection, so we don't want to have string concatenation in our docs. But placeholders in JDBC are cumbersome. JDBI (https://jdbi.org/) lets you do something simpler:

handle.execute("DELETE from promo_codes WHERE code IN(?, ?, ?)", codeOne, codeTwo, codeThree);

@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB docs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-doc-improvement no-issue-activity P-2 Normal priority; secondary task
Projects
None yet
Development

No branches or pull requests

3 participants