Results 1 to 2 of 2
- 04-10-2010, 06:09 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 16
- Rep Power
- 0
- 04-11-2010, 01:01 PM #2
so the problem is reading the user's form input string in this format into the Date database property ?
e.g.
Java Code:String formFieldDateValue = request.getParameter("myDate"); new SimpleDateFormat dateFormat("dd/MM/yyyy"); Date myDate = null; try { myDate = dateFormat.parse(formFieldDateValue); } catch (ParseException ex) { // this is where we handle the invalid date entered, } // and later on, in the jdbc insert part // assuming you are using prepared statements to insert Connection con = null; PreparedStatement stmt = null; try { con = // how ever you get the connection, e.g. data sourece stmt = con.prepareStatement("insert into my_table(date_value) values (?); stmt.setDate(1, myDate); stmt.executeUpdate(); } catch (SQLException ex) { // handle database errors here } finally { //close statement and connection. }
Similar Threads
-
Servlet - apache tomcat/glassfish server shuts down on servlet usage
By StewS in forum Java ServletReplies: 1Last Post: 12-02-2008, 12:23 AM -
Compare date input to database with current date
By hungleon88 in forum Advanced JavaReplies: 2Last Post: 11-25-2008, 08:10 AM -
Run servlet in HTTP server
By jithan in forum New To JavaReplies: 25Last Post: 10-16-2008, 10:10 AM -
Creating a Gregorian Calendar using a Date object gives date - 1
By prachi_goliwadekar in forum New To JavaReplies: 1Last Post: 05-08-2008, 08:32 PM -
Date/Time Servlet
By Java Tip in forum Java TipReplies: 0Last Post: 01-14-2008, 09:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks