Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6116243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:11:03+00:00 2026-05-23T15:11:03+00:00

I get 1-n selected months from a JList. Now I’d like to select rows

  • 0

I get 1-n selected months from a JList.
Now I’d like to select rows from a sqlite DB with the selected months.

Is there a way to do it the easy way to build the select string, e.g. with a loop and a LIKE statement?

resultSet = statement
        .executeQuery("SELECT sum(Betrag) FROM record WHERE strftime('%Y',Datum)='"
            + options.getList_years().get(options.getCurrent_year_index())
            + "' AND strftime('%m',Datum) LIKE '"
            + "02 || 04 || 12"  //Here are the months, 
            + "' AND Sektion LIKE '"
            + "%"
            + "' AND Inhaber LIKE '"
            + list_accounts.getSelectedValue()
            + "' AND Ausgabe='"
            + "true';");

Or has it to look that way?

strftime('%m',Datum)='02' OR strftime('%m',Datum)='04' OR trftime('%m',Datum)='12'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:11:03+00:00Added an answer on May 23, 2026 at 3:11 pm

    You should use an IN clause:

    ... AND strftime('%m',Datum) IN ('02', '04', '12')
    

    But you should definitely not use string concatenation to set parameters dynamically in your query. This is the best way to suffer from SQL injection attacks. Use prepared statements, with a ? placeholder for each of your parameter:

    SELECT sum(Betrag) FROM record WHERE strftime('%Y',Datum) = ? ...
    

    Learn more about prepared statements in the JDBC tutorial.

    You will indeed have to use some loop or utility to build the IN clause. StringUtils from commons-lang is useful here:

    "... AND strftime('%m',Datum) IN (" + StringUtils.repeat("?", ", ", months.size()) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone knows how to get selected text from other application using UI Automation and
How do I get the selected value from a dropdown list using JavaScript? <form>
How can I get the selected text (not the selected value) from a drop-down
Is it possible to get the selected row index from my table model? My
HTML Javascript question to get the selected value of a input-select I can use
I am trying to get the selected option from a dropdown and populate another
How to get Selected row index in DBGrid ? so Im using ADOQuery ->
Using this jquery code: <a href=javascript:void(0) id=m1>Get Selected id's</a> jQuery(#m1).click( function() { var s;
I am trying to get the selected items string out of a Spinner .
Im getting a -1 value when i try to get the selected item position

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.