Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting the date/time fields into Strings

 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
my sql statement looks like this:
update = "UPDATE vippass SET start = \"" + m + "\", email=\"" + email + "\" WHERE passcode=\"" + passcode + "\"";
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,
In that case I would rewrite your UPDATE statement as:

HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic