my dog learned polymorphism*
The moose likes JDBC and the fly likes JSP and SQL problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JSP and SQL problem" Watch "JSP and SQL problem" New topic
Author

JSP and SQL problem

Jeetendra S Ahuja
Greenhorn

Joined: Feb 11, 2012
Posts: 7
Sample Database
+-------+------+--------------+
| busno | fuel | date |
+-------+------+--------------+
| 1 | 19.6 | 16-09-2002 |
| 1 | 19.6 | 17-09-2002|
| 1 | 22.8 | 18-09-2002|
| 1 | 17.2 | 19-09-2002|
| 1 | 17.2 | 20-09-2002|
| 1 | 17.2 | 21-09-2002 |
| 1 | 17.2 | 22-09-2002|
| 2 | 17.2 | 23-09-2002 |
| 2 | 17.2 | 24-09-2002 |
| 2 | 17.2 | 25-09-2002 |
| 2 | 17.2 | 26-09-2002|
| 2 | 17.2 | 27-09-2002|
| 3 | 17.2 | 28-09-2002 |
| 3 | 19.7 | 29-09-2002 |
assume
A.jsp --> B.jsp

I have retrieved date in web page(say A.jsp) via util date object,now i had retrieved same date on other web page(B.jsp) via request.getParameter(),,,now i want to store that date in database,problem is that request.getParameter() gives string and in Database i have date DataType ,,so how to convert string date to sql date in JSP specially,, and after storing date :
I want to add fuel for a particular bus from UserDefined Date to UserDefined date....
I know this query:-select SUM(fuel) from fuel group by busno.
i dont know how to integrate between clause with it..... please help..i have to submit my project,,,asap....
Thanks Jeetendra Ahuja
Philip Thamaravelil
Ranch Hand

Joined: Feb 09, 2006
Posts: 99
Let me say first, doing this type of logic in a JSP violates many best practices.

What is sounds like your looking for is object serialization. Deflating an object (this case a java.util.Date), passing the string to another module, then re-inflating to the Object.

Now, implementing full-blown object serialization might be overkill for what you are wanting to accomplish, So IMO, I would use the java.text.SimpleDateFormat library to convert your date object to a string, then use the same library to get your java.util.Date object back.

BTW - java.util.Date can easily be converted to java.sql.Date. Have a look at the java.sql.Date constructors in it's API.

Best of luck.

Cheers,
Philip



Jeetendra S Ahuja
Greenhorn

Joined: Feb 11, 2012
Posts: 7
String s2=(request.getParameter("date"));
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date result = formater.parse(s2);

java.sql.Date date = new java.sql.Date(result);
Hey,,,philip after using this ,,even i am getting the error
Date(java.util.Date) constructor cannot find symbol..
Philip Thamaravelil
Ranch Hand

Joined: Feb 09, 2006
Posts: 99
Here's more of what I had in mind..




Let me suggest though, doing this type of task in JSP is inherently problematic and a poor practice. This should be done in an enterprise component such as a Servlet.

Cheers,
Philip
Philip Thamaravelil
Ranch Hand

Joined: Feb 09, 2006
Posts: 99
Jeetendra S Ahuja wrote:
Date(java.util.Date) constructor cannot find symbol..


You need to use the getTime() function.




Cheers,
Philip
Jeetendra S Ahuja
Greenhorn

Joined: Feb 11, 2012
Posts: 7
hey philip...,i did it under your guidance...
anyway,
CHEERS
Philip Thamaravelil
Ranch Hand

Joined: Feb 09, 2006
Posts: 99
That's terrific! Glad I could help.
Philip
 
wood burning stoves
 
subject: JSP and SQL problem
 
Similar Threads
current JSP page/file and included resources
Need help: jsp: include relative path question!
Changing the URL when using forward or redirect...
current JSP page v/s current JSP file!!
Relative URL specifications, JSP 1.2.1