This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extract Date from JSP and push to MySQL

 
Kavita Shivani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,
I have a date field in my JSP, I get it as a string in my controller through get parameter method. But from there I have no clue how do I convert it into date format and insert into database. Also I found in datebase that the date format is yyyy-mm-dd hh:mm:ss something like that. I assume there are ways of doing it and some standard way of doing it. Please suggest me on this.

thanks,
Kavitha.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the nice things about JDBC is, as a developer, you don't to worry about date format. For adding a date to the database create a valid java.sql.Date (similar to java.util.Date) object and using a PreparedStatement, such as ps, call ps.setDate(numericIndex,dateValue). The JDBC driver will handle the conversion of the date format once you move it to a valid Java object.

And as always I have to say... PLEASE DO NOT PUT JDBC CODE INSIDE A JSP!!! Move your JDBC code to a reusable utility class. JDBC code inside a JSP is inherently unsafe and not reusable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic