• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how calendar date uses in request.getparameter()?

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my website, I used calendar in input field in jsp using jquery.This is my code.




This is my input field




Now I want use request.getparameter() means what date user picks how can I use in it in request.getparameter? and also , I want to use it in preparestatement how can I use it in preparestatement?
Screenshot_19.png
[Thumbnail for Screenshot_19.png]
this is calendar.
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order for the date to become a requestParameter, it has to be submitted to the servlet. Where are you submitting? There is no form to submit.

Forget about datepicker for now. How would you submit a simple input field to the servlet?
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is form in jsp.



This is servlet code.


 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what happens when you run this code? Does it compile? Do you get an exception? If so, please provide the stacktrace.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my console lines, there are many more lines in console but site does not allow me to copy paste whole console lines here...

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '01/06/2016' for column 'Date' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3868)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3806)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2470)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2617)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2550)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Convert the date string into a proper java.util.Date object (using java.text.SimpleDateFormat), the use setDate.

Currently MySQL is trying to convert your date string based on its default format, and failing.
You shouldn't really be inserting into a DATE field using a String.


ETA: Do not make your SimpleDateFormat variable an attribute of your Servlet. It is not a threadsafe class.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone give me example of date in which request.getparameter()(suppose input field name is date in jsp form) used and preparestatement also used (servlet) to assign date in database? I tried things which explained in google but can not get it.....
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you followed Dave Tolls' advice?
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello, I have problem because I designed calendar, and by using calendar, user picks any date and I used request.getparameter() for that here is my jsp code.








and this is my servlet code :





I really don't understand what change should I make?
Screenshot_22.png
[Thumbnail for Screenshot_22.png]
This is the calendar, user selecting date by this calendar.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem is not with getParameter. Problem is with conversion of date.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly.
You have received a date string from the client (your "date" parameter).
You now need to turn that into something that is easy for the JDBC side of your code to understand.
Since the "Date" column is a DATE type in your database, you should parse you string into a java.util.Date object.

I gave links on how to do that in my earlier post.
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take Dave's advice. You need to remember that all parameters from input fields are going to be Strings. It doesn't matter what you enter in that field (numbers, letters, dates), when it's submitted it becomes a String. You have to convert it to the data type that you need, in this case a java.util.Date object, if that is what your database is expecting.
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic