• Post Reply Bookmark Topic Watch Topic
  • New Topic

how calendar date uses in request.getparameter()?

 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • 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.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
This is form in jsp.



This is servlet code.


 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • 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)
 
Dave Tolls
Ranch Hand
Posts: 2369
25
  • Mark post as helpful
  • send pies
  • 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
  • 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.....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65661
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you followed Dave Tolls' advice?
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • 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.
 
Swastik Dey
Rancher
Posts: 1721
8
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem is not with getParameter. Problem is with conversion of date.
 
Dave Tolls
Ranch Hand
Posts: 2369
25
  • Mark post as helpful
  • send pies
  • 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: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!