Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clicking on text retrieve data from database

 
ammuswar kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
mocca az
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
mocca az
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic