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 converting the date/time fields into Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "converting the date/time fields into Strings " Watch "converting the date/time fields into Strings " New topic
Author

converting the date/time fields into Strings

sam davis
Greenhorn

Joined: Jun 16, 2003
Posts: 18
Hello,
I have a field of date/time as a part of my sql statement to update the database. I want to convert that field into String and then, use that string in my SQL. This is wut im doing:
String m = (new SimpleDateFormat("EEE' 'yyyy-MM-dd' 'HH:mm:ss")).format((java.util.Date) start, new StringBuffer(), new FieldPosition(DateFormat.YEAR_FIELD)).toString();
Is this a right way of converting???..any suggestions or help would be greatly appreciated.
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
It is difficult to know whether what you are trying to do is correct without seeing the SQL statement.
I'd prefer to use a PreparedStatement rather than do all the datetime formatting that you are doing as I feel it is more readable.
i.e.

HTH


Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
sam davis
Greenhorn

Joined: Jun 16, 2003
Posts: 18
hello,
my sql statement looks like this:
update = "UPDATE vippass SET start = \"" + m + "\", email=\"" + email + "\" WHERE passcode=\"" + passcode + "\"";
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
Hi Sam,
In that case I would rewrite your UPDATE statement as:

HTH
 
jQuery in Action, 2nd edition
 
subject: converting the date/time fields into Strings
 
Similar Threads
how to get out parameter from store procedure?
parent child relation ship
I'm trying to send XML to a servlet but the input is always null
Has anyone seen this error before??
hi urgent