This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Conversion of String(dd/mm/yyyy) into java.sql.date format  RSS feed

 
Vivek Kr Agrawal
Ranch Hand
Posts: 51
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am taking a string in textBox in format(dd/mm/yyyy). Now i have to convert it in format java.sql.date to store in Oracle Database whose datatype is again date.
Thanks in advance!!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16043
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use class java.text.SimpleDateFormat to parse the string into a java.util.Date object.

If you're inserting it into the database using JDBC, you'll have to convert that to a java.sql.Date (unfortunately, there are two classes called Date - one in the package java.util and another in the package java.sql). Converting from java.util.Date to java.sql.Date is easy - have a look at the constructors of java.sql.Date and the methods of java.util.Date in the documentation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!