Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get and Set Date

 
zeb usman
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am new to Java.I am working on a small project where i have to store some Strings and date into database using servlet MVC.
I Have created a java class in Model package,in which i have created a parameterized Function to make connection.
 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "getdate" what exactly does that mean? It sounds like you're hoping to get a date from somewhere. Have you thought about where you might get it from? I notice you got a "name" from the request, would you be getting the date from the request as well? You need to explain your design to us.
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zeb,
//How to getdate here??

Which date are you trying to retrieve ? Is it the current system date ? Is it the date when the servlet request is processed ? or is it someother date from the application ?
 
zeb usman
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to insert current system date into database. When i write String d=request.getParameter ("Current");
Its showing incompatible type.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parameters are strings. If you need a Date, you'll need to convert it. See SimpleDateFormat.
 
zeb usman
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You! Can You please post the exact code ??
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First we would like you to attempt at writing the code , then when you come up with issue , we will surely help you and point you in the right direction. As Bear said take a look at how to convert the String parameter then try to attempt it out.
 
zeb usman
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String datestr="dd-MM-YY"; SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
Date d=formater.parse(datestr);

I tried many times and i end up with this code which showing
Incompatible types
Required java.sql.date
Found java.sql.date

 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ncompatible types
Required java.sql.date
Found java.sql.date


Which Date have you imported ? java.sql.Date or java.util.Date ? Remember that java.sql.Date is just a wrapper around the java.util.Date to allow JDBC to identify the date . see Javadocs -- here . You may need the java.util.Date .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic