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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:43:10+00:00 2026-05-29T14:43:10+00:00

Having trouble with an sql statement to retrieve a record between two timestamps. This

  • 0

Having trouble with an sql statement to retrieve a record between two timestamps. This is just giving me a NullPointerException and I think it’s just a syntax error, II’ve been searching around and I couldn’t find anything. This is the statement:

private static final String strGetRecordByDate =
    "SELECT * FROM APP.MYTABLE " +
    "WHERE MYDATE >= ?, AND MYDATE <= ? " +
    "VALUES (?, ?)";

creating the statement:

stmtGetRecordByDate = dbConnection.prepareStatement(strGetRecordByDate);

The nullpointer exception shows on stmtGetRecordByDate.clearParameters():

public Vector getRecordByDate(Date datefrom, Date dateto){
    Vector<String> records = new Vector<String>();
    ResultSet results = null;
    java.sql.Date sqlDatefrom = new java.sql.Date(datefrom.getTime());
    java.sql.Date sqlDateto = new java.sql.Date(dateto.getTime());
    try {           
        stmtGetRecordByDate.clearParameters();
        stmtGetRecordByDate.setDate(1, sqlDatefrom);
        stmtGetRecordByDate.setDate(2, sqlDateto);
        results = stmtGetRecordByDate.executeQuery();
        while (results.next()) {
            int id = results.getInt(1);
            String entry = results.getString(2);
            records.add(entry);
        }
    } catch(SQLException sqle) {
        sqle.printStackTrace();
    }
    return records;
}

The Rest of the queries and statements work fine so I know that the database itself is fine there is just something wrong with this one.

Any suggestions would be great.
Thanks!

  • 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-29T14:43:12+00:00Added an answer on May 29, 2026 at 2:43 pm

    You can’t use a VALUES in that context and you have a stray comma in your WHERE clause; you want this:

    private static final String strGetRecordByDate =
            "SELECT * FROM APP.MYTABLE " +
            "WHERE MYDATE >= ? AND MYDATE <= ?";
    

    You could also use BETWEEN:

    private static final String strGetRecordByDate =
            "SELECT * FROM APP.MYTABLE " +
            "WHERE MYDATE BETWEEN ? AND ?";
    

    but that’s just a matter of style.

    I’m not certain about the Java side of things but you’re probably getting a null in stmtGetRecordByDate because of your invalid SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble with the following SQL statement. I have had this issue
I'm having trouble figuring out the SQL statement to retrieve a specific set of
I'm having trouble with using an IF statement within this sql-server query. What I
I'm having trouble converting the following SQL-statement to LINQ-to-entities: SELECT l.* FROM locations l
I'm having some trouble with an SQL statement that have to find the number
Hey smarties. I'm having trouble with the following SQL statement. I know that I
Hey guys i want to execute my SQL statement but im having synatx trouble,
I'm having trouble finding the syntax for a statement (or whether or not it's
I'm having trouble trying to define the SQL query for this table: There's a
I am having trouble with a simple DELETE statement in SQL with unexpected results

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.