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

  • Home
  • SEARCH
  • 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 6330177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:49:25+00:00 2026-05-24T17:49:25+00:00

I am using jdbc to call a sql query …. where mydate like ‘?%’

  • 0

I am using jdbc to call a sql query “.... where mydate like '?%' ”
and I want to pass the parameter to the query with:

PreparedStatement ps;  
ps.setDate(1, new java.sql.Date.valueOf("2000-01-13"));

But this last line is not compiling, and I don’t know why. When i enter the date directly into the query above, as in “.. where mydate like ‘2000-01-13%'”, it works.

  • 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-24T17:49:26+00:00Added an answer on May 24, 2026 at 5:49 pm

    Apart from the basic compilation error (just remove new), I spot 2 serious problems:

    1. Given the fact that LIKE works, your mydate field is apparently of a varchar type instead of a fullworthy date, datetime or timestamp type. This is recipe for problems. You should always use the right data type for the information the field holds.

    2. % cannot be put after preparedstatement placeholder ?. It has to be set in the value directly. However, this works with String values only (and thus varchar field types). For a fullworthy date, datetime and timestamp type you’d rather use =, <, > or BETWEEN instead.

    There are 2 solutions:

    1. Change the data type of the field to be a real date, datetime or timestamp, so that you can use the proper SQL syntax such as WHERE mydate BETWEEN ? AND ?.

    2. Use preparedStatement.setString(1, "2000-01-13%") instead and remove those singlequotes around the placeholder ? as well so that it ends like WHERE mydate LIKE ?.

    See also:

    • Preparedstatement tutorial
    • MySQL data types
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using JDBC, I often come across constructs like ResultSet rs = ps.executeQuery(); while
i'm using jdbc to work with my db. I want to store a HashMap
I have a java-application using JDBC for database interaction. I want to do a
I have an org.springframework.jdbc.object.StoredProcedure which I am using to call a DB function. I
I'm connecting to SQL Server (2005) through Java using the Microsoft SQL Server JDBC
I am calling an 2005 MS SQL Server stored procedure using the MS JDBC
I would like to call this stored procedure with jdbc: sp_msforeachtable ALTER TABLE ?
We are using the jdbc-odbc bridge to connect to an MS SQL database. When
I am trying to connect the Sql Server 2008 R2 with java using JDBC.I
I'm using JDBC to get a large amount of data. The call completes successfully,

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.