Link to home
Create AccountLog in
Avatar of osama120
osama120

asked on

PreparedStatement show only date with out time

i have this method i use in update query to update the modify date the method only show the date without the time
 java.sql.Date date = getCurrentJavaSqlDate();
                 ps.setDate(6,date);
the method is  
  public static java.sql.Date getCurrentJavaSqlDate() {
    java.util.Date today = new java.util.Date();
    return new java.sql.Date(today.getTime());
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Use java.sql.Timestamp not Date
(and ps.setTimestamp)
ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
here is how you create timestamp from string!

http://www.jguru.com/faq/view.jsp?EID=315648
The equivalent to your current utility method would be

public static java.sql.Date getCurrentJavaSqlTime() {
	return new java.sql.Timestamp(System.currentTimeMillis());
}

Open in new window

osama120, can you tell me why my answers were ignored please?
Avatar of osama120
osama120

ASKER

when i try it it give incompatable type
public static java.sql.Date getCurrentJavaSqlTime() {
      return new java.sql.Timestamp(System.currentTimeMillis());
}
and the soultion is this
import java.sql.Timestamp;
 java.sql.Timestamp date = getCurrentJavaSqlDate();
                 ps.setTimestamp(6,date);

public static java.sql.Timestamp getCurrentJavaSqlDate() {
    java.util.Date today = new java.util.Date();
    return new java.sql.Timestamp(today.getTime());

>>when i try it it give incompatable type

Sorry that was a typo. It should have been the below. But that's not the point really - i'm talking about your ignoring the first comments in this question, posted by me...
public static java.sql.Timestamp getCurrentJavaSqlTime() {
      return new java.sql.Timestamp(System.currentTimeMillis());
}

Open in new window