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 8887413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:48:08+00:00 2026-06-14T21:48:08+00:00

I have a table where I have to do a SELECT … BETWEEN start_date

  • 0

I have a table where I have to do a SELECT ... BETWEEN start_date AND end_date, as well as insert Date values into the same table.

I read things like:

java.util.Date now = new java.util.Date();
pStmt.setDate( 1, new java.sql.Date( now.getTime() ) );
pStmt.setTimestamp( 2, new java.sql.Timestamp( now.getTime() ) );
pStmt.executeUpdate();

But that kind of code sets or gets the current date, doesn’t it? I want to insert and select custom dates myself.

I also read it here at StackOverflow:

SELECT *
FROM myTable
WHERE ( YEAR(myfield) = '2009')
  AND ( MONTH(myfield) = '1')

Is it also possible to make the Date fields String, then use StringTokenizer to extract only the day, month or year information and use them in a SELECT similar to this code? (In case my first – and simpler – idea is impossible.)

So until now, there’s two possible solutions. I also need to know which one is faster since the database accessed is in a fail-safe / critical system (a bank) with lots of data.

  • 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-06-14T21:48:09+00:00Added an answer on June 14, 2026 at 9:48 pm

    The first approach is better, because you were able to use date functions to manipulate values.

    private void executeQuery(java.util.Date startDate, java.util.Date endDate) throws SQLException {
      Connection conn = null;
      PreparedStatement pstmt = null;
      try {
        conn = getConnection();
        String query = "select ... between ? and ?";
        pstmt = conn.prepareStatement(query);
        pstmt.setDate(1, new java.sql.Date(startDate.getTime()));
        pstmt.setDate(2, new java.sql.Date(endDate.getTime()));
        //return results
        ResultSet rs = pstmt.executeQuery();
        rs.last();
        System.out.println("last row = " + rs.getRow());
      } finally {
        if (pstmt != null) {
          pstmt.close();
        }
        if (conn != null) {
          conn.close();
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-table SELECT query which compares column values with itself like below:
I have a table select * from table values returning are login id |
Summary : I have a table populated via the following: insert into the_table (...)
I have the following table Select * from Peeps Id Name Age 1 Sam
I have Table A. How can I select from Table A to get Table
I have a table. In this table have select element. How can I find
i have users table and i have posts table i want select from users
I have table with 3 columns A B C. I want to select *
suppose I have SELECT * FROM table t GROUP BY j HAVING condition_one OR
I have users table and want to SELECT some rows by bitmask criteria. I'll

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.