The issue of data storage is unrelated to the issue of data display. You will need to provide the DB with a data format it can store.
The first thing you should do is switch back to using the PreparedStatement. It will do many things for you, including the handling data types that you're currently struggling with. You would not use "setString" for date and timestamp fields, but methods that are appropriate for those data types.
Another thing PreparedStatement does is to protect you from SQL injection attacks - your current code is wide open to those attacks.
Thanks for the quick response, here first of all, i'm trying to print the query and lateron, once i get the date in the format that i want, i'll change the setString to setDate or corresponding things, her the date the query i'm printing is not in the proper format that i want.
but when i get this type of date in output it is throwing the exception as mentioned above.
What is the "output"? I don't see code that would output dates anywhere. So I'm not clear which line of code produces the exception you mention.
If you're talking about printing the query, then that calls the Date.toString method, the output of which is irrelevant to either storing the date in the DB, or displaying the date in a web page. (Date objects have no inherent format, they're just data.)
So I repeat: start by using PreparedStatement so that the storing in the DB works.
As Ulf has said, you are mixing displaying your dates up with how they are stored.
Your Date fields in the database do not have a format...just as java.util.Date's do not have a format.
So parse the dates supplied by the user into a Date and use a prepared statement to store that in the relevant date column in your table.
When you read it out for display then format the returned Date into the form you require.
I'll say it again: the way the Date object is printed in that SQL string is completely irrelevant. If you think it is then you have misconceptions about how Date objects and their parsing and formatting works. As I've also said, you should be using PreparedStatement (and not care about what SQL is generated). What matters is that you are able to store it in the DB, no?
How dates are formatted in the input and output HTML pages are separate matters that have nothing to do with how the date is stored in the DB.