aspose file tools*
The moose likes Servlets and the fly likes clicking on text retrieve data from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "clicking on text retrieve data from database" Watch "clicking on text retrieve data from database" New topic
Author

clicking on text retrieve data from database

ammuswar kumar
Greenhorn

Joined: Aug 19, 2001
Posts: 27
hi
need ur help very urgent send it today if possible:
USING JAVA SERVLETS
--------------------
task:
there is a data base(access)- table :3 fields
1.id
2.date.
3.content
now i have to create a java servlet which will retieve data from the above
database by clicking on a text(<a href=""> )
example click here to get todays content
now the sql statement should check the date with the system date and retrieve
the result
so if u click on the href which is <a href="">today</a> then it should display the content from the table depending on , checking todays date with system date

please send it today ...urgent
amit
[This message has been edited by ammuswar kumar (edited August 20, 2001).]
Shama Khan
Ranch Hand

Joined: Aug 14, 2000
Posts: 185
The answer could be find within a week by reading
"JAVA Servlet Programming" by Jason Hunter and William Crawford
I hope I have been helpful
Shama


Shama
mocca az
Ranch Hand

Joined: Mar 07, 2001
Posts: 93
use java.util.Date class to get current date/time, whatever you need and store it to the variable exp.
where you have your link
<a href="servletName?param=todaysDate>click here</a>
in your servlet request.getParameter("param") will have the value of the todaysDate which will be system time.
In your sql statement (select content from table where date = '" param"'")
take care
ammuswar kumar
Greenhorn

Joined: Aug 19, 2001
Posts: 27
Originally posted by mocca az:
use java.util.Date class to get current date/time, whatever you need and store it to the variable exp.
where you have your link
<a href="servletName?param=todaysDate>click here</a>
in your servlet request.getParameter("param") will have the value of the todaysDate which will be system time.
In your sql statement (select content from table where date = '" param"'")
take care

hi mocca
thanks fro throwing a light on my quest but since i am quite new to this can u please elaborate on what do u mean by todaysdate
<a href="servletName?param=todaysDate>click here</a>
and how is it u are going to store system date (today date) in a variable
see i got u r point that by click the href the param value(i.e todaysdate)is going to passes to the servlet but what is the content of todaysdate i mean what value does it hold , may be i am getting confused , if u could please explain once again.
thanks
mocca az
Ranch Hand

Joined: Mar 07, 2001
Posts: 93
Greetings!
I'm sorry, i see where i got you confused. Copy and paste following code and play with it a little bit. You will have to figure out how to get the date in format you need it. Check documentation for the Date class in JDK. It is under java.util.
------------------------------------------------------
today.jsp
------------------------------------------------------
<%@ page import = "java.util.*;" %>
<html>
<body>
<%
Date today = new Date();
out.println("Today is " + today);
%>
<a href="news.jsp?myDate=<%= today %>"> Today's News </a>
</body>
</html>
----------------------------------------------------
***************************************************************
-------------------------------------------------------------
news.jsp
---------------------------------------------------------------
<% String todayIs = request.getParameter("myDate"); %>
Request variable has received follwing value -->
<% out.println(todayIs); %>
<br>
<% String sqlStatement = "SELECT * FROM TABLE WHERE DATE = '" + todayIs + "'"; %>
My SQL statement is as follows:
<br>
<% out.println(sqlStatement); %>
---------------------------------------------------------------
Hope this helps
m, phx

ammuswar kumar
Greenhorn

Joined: Aug 19, 2001
Posts: 27
Originally posted by mocca az:
Greetings!
I'm sorry, i see where i got you confused. Copy and paste following code and play with it a little bit. You will have to figure out how to get the date in format you need it. Check documentation for the Date class in JDK. It is under java.util.

hi mocca
u did a great job sending me the code and i really appreceate ur help ,only fix on mind left is u send the code in jsp and not in java servlets (my original poblem), do both work in the same fashion?
thanks anyways , i am obliged
regards
amit
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
As mentioned earlier, I think it's best if you check out one of the servlets books out there. It will help you out. Some might even have examples of what you are trying to do. Java Servlet programming by Jason Hunter, and Core Servlets & JSP by Marty Hall are two good ones.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
mocca az
Ranch Hand

Joined: Mar 07, 2001
Posts: 93
Yes. Both work in the same fashion, but as Bosun said, it will be best for you to get a book or something and start working from the bottom.
 
jQuery in Action, 2nd edition
 
subject: clicking on text retrieve data from database