Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Your buns are mine! But you can have this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic