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

string to java.util.Date and then to java.sql.Date  RSS feed

 
Mullin Yu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i have a simple question:

1. receive a string in the format, yyyymmdd
2. add ONE day to it, i.e. yyyymmdd+1 =>20050411+1 => 20050412
3. change it to java.sql.Date and then pass to PreparedStatement's setDate

PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setDate(1, newSQLDate);

how to do it?
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) construct a date object using your String, you'll need DateFormat to parse it.
2) get an instance of Calendar, set the time to that of the Date object, and use the add method in Calendar.
3) construct and instance of java.sql.Date using the long you get back from Calendar when calling getTimeInMillis
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!