File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Get and Set Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Get and Set Date" Watch "Get and Set Date" New topic
Author

Get and Set Date

zeb usman
Greenhorn

Joined: Apr 12, 2013
Posts: 10
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 11, 2011
Posts: 440

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 ?


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
zeb usman
Greenhorn

Joined: Apr 12, 2013
Posts: 10
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

Joined: Jan 10, 2002
Posts: 61221
    
  66

Parameters are strings. If you need a Date, you'll need to convert it. See SimpleDateFormat.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
zeb usman
Greenhorn

Joined: Apr 12, 2013
Posts: 10
Thank You! Can You please post the exact code ??
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

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

Joined: Apr 12, 2013
Posts: 10
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

Joined: Aug 11, 2011
Posts: 440

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
 
subject: Get and Set Date