Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Data from access database according to today date using java

 
Sagar Deshmukh
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I google this problem didn't get any solution
I want to retrieve data from ms access database according to today date, i have write below program but getting error



Error : Data type mismatch in criteria exception

please help waiting for helpful reply

 
Richard Tookey
Bartender
Pie
Posts: 1166
17
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be using a PreparedStatement ( http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html ) with a java.sql.Date initialized to today using System.currentTimeMillis() when constructing.
 
Sagar Deshmukh
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Richard for reply,
But prepairedStatement is use for update and insert how do i use it for select clause

and i have change d1 = new java.sql.Date(d.getTime()); but still i am getting same error

Really confuse about this date
please help
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But prepairedStatement is use for update and insert how do i use it for select clause


What does make you think this? A cursory look into the API docs of PreparedStatement (and not prepairedStatement ) reveals:
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Deshmukh wrote:
But prepairedStatement is use for update and insert how do i use it for select clause


An excerpt from the tutorial hinted to by Richard goes:


Executing PreparedStatement Objects

As with Statement objects, to execute a PreparedStatement object, call an execute statement: executeQuery if the query returns only one ResultSet (such as a SELECT SQL statement), ...
 
Sagar Deshmukh
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends got it using below changes



Thanks for your support
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it's good to see that you followed the wise advice that was given to you. Oh wait.... you didn't.

Your code is lesser for it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic