Link to home
Create AccountLog in
Avatar of Jeevanjosh
Jeevanjosh

asked on

how can i get the table values wich is in String and i want convert into date

Hi  
I need the help in the following code
1,i am selecting all the value from the table<bookings> where the date is in the String format
after selecting how can i convert my all date values into date format (more than3000records)
2.after converting i have to comapre with todays date so that i can get all the records  ,where the booking date is > todays date
3. pls kindly look into the attachment and kindly answer me step by step the requirement is urgent

Thank You
Reg
Jeevanjosh



onebookings.txt
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

        Hi!

There are several ways to do that see examples
http://www.java2s.com/Code/Java/Database-SQL-JDBC/ConstructjavasqlTimestampfromstring.htm
http://www.java2s.com/Code/Java/Database-SQL-JDBC/Date-Time-Timestamp.htm
http://www.java2s.com/Code/Java/Development-Class/Calendar-Date.htm
But if you are selecting direct from the database and want to convert the datetime-string into datetime/timestamp then you can do that by simply use the database built in date functions.
I'm guessing that you are using DB2 so that would be something like
select DATE(TIMESTAMP(stringdatefield)) mydatefield
from table where TIMESTAMP(stringdatefield)) > CURRENT TIMESTAMP;

Regards,
   Tomas Helgi
Avatar of Jeevanjosh
Jeevanjosh

ASKER

Hi ThomasHelqi

Hi Thomas, thank you so much for the kind solution,but i am not able to get it
i am working in the jsp,since i am the beginner pls kindly expalin.
The code  which i copyed is the  one wher i want to convert my string(date-is variable name in the table) into date
this code will list all the values form the table<rbookings>
since i am the bignner,pls kindly help and point out for me,
1.what coding i have to use for converting
2.and where should i include in my coding
3.how can i check the out put
4.after i selected   and converted i have to comapre with todays date to get the set of  values wich  is  > than today
kindly   help me step by step
it is very urgent ,kindly guide
Thank you so much Thomas
very very kind request ,very very urgent

regards
josh


<%@page import="java.util.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.text.*"%>
<%@page import="java.util.Calendar"%>
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
String sql = "select date,purpose,status,rid from room_booking ";
 
ResultSet rs = stmt.executeQuery(sql);
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("DATE");
	purpose = rs.getString("PURPOSE");
	status = rs.getString("STATUS");
	rid = rs.getInt("RID");
 
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
 
    records.addElement(bean);
        
    }
 
 %>
  
<html>
<head> 
 
<title>ROOM BOOKING LIST</title>
 
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
          
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
  	
	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
 
<%}%>
 
 
</table>
Total Records:
<%=records.size()%>
 
 
</body>
</html>

Open in new window

onebookings.txt
Hi  TomasHelqi

can i kindly get some reply from your side,expecting your solution for the abve problem

Thank you

regards
jeevanjosh
thank you
SOLUTION
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi TomasHelqi

Thank you so much for answering me according to my need & to my level, so kind of you,
i tryed the coding it gives 2errors for me
1.illegal Modifier for the local class ComapreDates,only one abstract or final is permitted
2.The Method main cannnot be decalared static;Static method can only be dclared in a static or top level type,date cannot be resolved.

 i passed my vaiable wich is the table value in the
Kindly help me in the this two errors
Thank you
with Thanks
JeevanJosh


<%@page import="java.util.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
 
<%
public class CompareDates{//error 1
public static void main(String[]args) throws ParseException{//error 2
 DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
 
 Date d1 = df.parse("date"); // passed  my table value is that is cooect
 	Date today = new Date();
 		String relation;
 		if (d1.equals(today))
 	relation = "the dame as date";
 		else if(d1.before(today))
 			relation = "before";
 				else
 			relation = "after";
 	System.out.println(d1+ "is" + relation +' '+ today);
 		
		
	}
}
%>
 
 
 
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
//String dateStr ="01-05-2001";
//java.text.SimpleDateFormat dateFormat = new java.util.text/SimpleDateFormat("dd-mm-yyyy")
//java.text.SimpleDateFormat dateFormat = new java.util.text.SimpleDateFormat("dd-mm-yyyy");
//java.util.Date roomdate = dateFormat.parse(dateStr);
//Format frmt = new SimpleDateFormat("dd-mm-yyyy");
//String dt = frmt.format(roomdate);
 
 
//String sql = "select DATE(TIMESTAMP(05-05-2001))date from room_booking where TIMESTAMP(05-05-2001)) > CURRENT TIMSTAMP ";
 
//select DATE(TIMESTAMP(stringdatefield)) mydatefield 
//from room_bookings where TIMESTAMP(stringdatefield)) > CURRENT TIMESTAMP;
 
 
 
String sql = "select date,purpose,status,rid from room_booking ";
 
 
ResultSet rs = stmt.executeQuery(sql);
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("DATE");
	purpose = rs.getString("PURPOSE");
	status = rs.getString("STATUS");
	rid = rs.getInt("RID");
 
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
 
    records.addElement(bean);     
    
    }
     
 %>
 
 
 
 
 
<head> 
 
<title>ROOM BOOKING LIST</title>
 
<script type="text/javascript">
 
var mydate= new Date()
var theyear=mydate.getFullYear()
var themonth=mydate.getMonth()+1
var thetoday=mydate.getDate()
var currentday=(thetoday+"/"+themonth+"/"+theyear)
 
document.write("Today's date is: " +currentday)
 
</script>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
 
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>

Open in new window

bookings.txt
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi  TomasHeqi

Thank you so much for the rply,i changed my Main procedure,like below,error 2 is not appearing now, but still i have the (error 1:illegal modifier fro the class CompareDates:only one of abstract or final is permitted.)

kindly help to proceed ,
thank you so much
regards
jeevanjosh

<%@page import="java.util.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
 
<%
public class CompareDates{
public String getCompareResult(String date){
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = df.parse("date");
 
	Date today = new Date();
		String relation;
	if (d1.equals(today))
 	relation = "the dame as date";
	else if(d1.before(today))
	relation = "before";
	else
	relation = "after";
 	System.out.println(d1+ "is" + relation +' '+ today);
 		
 }
 }
 
%>
 
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
//String dateStr ="01-05-2001";
//java.text.SimpleDateFormat dateFormat = new java.util.text/SimpleDateFormat("dd-mm-yyyy")
//java.text.SimpleDateFormat dateFormat = new java.util.text.SimpleDateFormat("dd-mm-yyyy");
//java.util.Date roomdate = dateFormat.parse(dateStr);
//Format frmt = new SimpleDateFormat("dd-mm-yyyy");
//String dt = frmt.format(roomdate);
 
 
//String sql = "select DATE(TIMESTAMP(05-05-2001))date from room_booking where TIMESTAMP(05-05-2001)) > CURRENT TIMSTAMP ";
 
//select DATE(TIMESTAMP(stringdatefield)) mydatefield 
//from room_bookings where TIMESTAMP(stringdatefield)) > CURRENT TIMESTAMP;
 
 
 
String sql = "select date,purpose,status,rid from room_booking ";
 
 
ResultSet rs = stmt.executeQuery(sql);
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("DATE");
	purpose = rs.getString("PURPOSE");
	status = rs.getString("STATUS");
	rid = rs.getInt("RID");
 
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
 
    records.addElement(bean);     
    
    }
     
 %>
 
<head> 
 
<title>ROOM BOOKING LIST</title>
 
<script type="text/javascript">
 
var mydate= new Date()
var theyear=mydate.getFullYear()
var themonth=mydate.getMonth()+1
var thetoday=mydate.getDate()
var currentday=(thetoday+"/"+themonth+"/"+theyear)
 
document.write("Today's date is: " +currentday)
 
</script>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
 
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>

Open in new window

SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi Tomas Heqi
 Thank you so much , i changed the symbol into <%!
When i include the ! symbol i am getting two different errors
error 1:this method must return a result of type String
error 2:Unhandled exception type ParseException

pls kindly help me

with  lots of thanks
Jeevanjosh


<%@page import="java.util.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
<%!
 
public class CompareDates{//error 1
public String getCompareResult(String date){ 
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = df.parse("date");//error 2
 
	Date today = new Date();
		String relation;
	if (d1.equals(today))
 	relation = "the dame as date";
	else if(d1.before(today))
	relation = "before";
	else
	relation = "after";
 	System.out.println(d1+ "is" + relation +' '+ today);
 		
 }
 }
 
%>
 
 
 
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
//String dateStr ="01-05-2001";
//java.text.SimpleDateFormat dateFormat = new java.util.text/SimpleDateFormat("dd-mm-yyyy")
//java.text.SimpleDateFormat dateFormat = new java.util.text.SimpleDateFormat("dd-mm-yyyy");
//java.util.Date roomdate = dateFormat.parse(dateStr);
//Format frmt = new SimpleDateFormat("dd-mm-yyyy");
//String dt = frmt.format(roomdate);
 
 
//String sql = "select DATE(TIMESTAMP(05-05-2001))date from room_booking where TIMESTAMP(05-05-2001)) > CURRENT TIMSTAMP ";
 
//select DATE(TIMESTAMP(stringdatefield)) mydatefield 
//from room_bookings where TIMESTAMP(stringdatefield)) > CURRENT TIMESTAMP;
 
 
 
String sql = "select date,purpose,status,rid from room_booking ";
 
ResultSet rs = stmt.executeQuery(sql);
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("DATE");
	purpose = rs.getString("PURPOSE");
	status = rs.getString("STATUS");
	rid = rs.getInt("RID");
 
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
 
    records.addElement(bean);     
    
    }
     
 %>
 
<head> 
 
<title>ROOM BOOKING LIST</title>
 
<script type="text/javascript">
 
var mydate= new Date()
var theyear=mydate.getFullYear()
var themonth=mydate.getMonth()+1
var thetoday=mydate.getDate()
var currentday=(thetoday+"/"+themonth+"/"+theyear)
 
document.write("Today's date is: " +currentday)
 
</script>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
 
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>

Open in new window

SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi Tomas helqi

Thank you  for piont out my mistake ,i changed the line into as you said
Now i am getting only the error 2(i.e) JavaCompile:Unhandled exception type ParseException
on line 19(i.e)Date d1 = df.parse(date)

Kindly help me in this  
Thank you

with thanks
Jeevanjosh


<%@page import="java.util.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
<%!
 
public class CompareDates{//error 1
public String getCompareResult(String date){ 
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = df.parse("date");//error 2
 
	Date today = new Date();
		String relation;
	if (d1.equals(today))
 	relation = "the dame as date";
	else if(d1.before(today))
	relation = "before";
	else
	relation = "after";
 	System.out.println(d1+ "is" + relation +' '+ today);
 		
 }
 }
 
%>
 

Open in new window

If you look at my example that I posted earlier and your code and you would see the difference. :)
If not then I can give you the answer.
If you look at the function getCompareResult(String date) a variable named date is passed to it right ?
The value of this variable is a string which represents a date in a particular format.
To change this value to a java class called Date you pass  the variable through another class called SimpleDateFormat which formats the value to the format "yyyy-MM-dd".
So if you look at the line 19 which is in error you see that you ar passing a string value "date" in stead of the variable date.
Remove the " from the "date" and the error is gone. :)

Regards,
    Tomas Helgi

Hi tomas
 Sorry about that , i made a mistake
 after i taken the " " the also it gives the same error

 
public class CompareDates{
public String getCompareResult(String date){ 
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = df.parse(date);
 
 	Date today = new Date();
	String relation;
	if (d1.equals(today))
 	relation = "the same as date";
	else if(d1.before(today))
	relation = "before";
	else
	relation = "after";
 	return df.format(d1) + "is" + relation +' '+ df.format(today); 
 	
 		
 }
 }
 
%>

Open in new window

Print out the value of the string variable you pass to the function
before calling it to see what is in it.
If the value is not in an accepted dateformat then you get an ParseException.

Regards,
   Tomas Helgi
Hi Toams Helqi
Is this is correct way   wich i have done, if not pls kindly  give me the coorected statement ,
 then also it is as the same error .

Thank you so much
with thanks
Jeevanjosh

<%!
public String getCompareResult(String date){
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(date);
 	     
    Date d1 = df.parse(date); 
 	Date today = new Date();
 	String relation;
 	if (d1.equals(today))
 	    relation = "the dame as date";
 	else if(d1.before(today))
 	    relation = "before";
 	else
 	    relation = "after";
 	return df.format(d1) + "is" + relation +' '+ df.format(today); 				
}
 
%>

Open in new window

This is one way to debug it yes.
Then you have the date put out into the SystemOut.log of your web-application server
or if you run it inside your IDE tool you should have a window that outputs the web-apps systemout.log.
Another way to print out the date is directly to the web-page's output that is
skip the keyword System leaving only out.println(date) and the date will show up
in one line of your webpage. But that I wouldn't do unless you can't see it in the Systemout.log file /window.

Regards,
    Tomas Helgi

Hi Tomas Heli

Thank you so much , i am waiting for from morning, thank you so much for the kind reply
How can i solve the problem

i am still having the error, JavaCompile:Unhandled exception type ParseException

kindly pls help me , i am expecting  ur kind answer

Thanks a lot


<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
<%!
public class CompareDates{
public String getCompareResult(String date){
  DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(date);
 Date d1 = df.parse(date); //error line JavaCompile :unhandled exception
 Date today = new Date();
 String relation;
 if (d1.equals(today))
 relation = "the same as date";
  else if(d1.before(today))
   relation = "before";
 	else
 	    relation = "after";
 	  return df.format(d1) + "is" + relation +' '+ df.format(today); 			
 	  
 	  }
 }	
%>
 
 
 
 
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
String sql = "select date,purpose,status,rid from room_booking ";
//String sql = "select [date],purpose,status,rid from room_booking where convert(datetime,Substring([date],5,4)+Substring([date],1,4),112)> getdate()";
//string sql = "select [date],purpose,status,rid from room_booking where convert (datttime ,Substring ())"
 
ResultSet rs = stmt.executeQuery(sql);
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("date");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	rid = rs.getInt("rid");
 
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
 
    records.addElement(bean);     
    
    }
     
 %>
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>

Open in new window

     
hmmm, this is again my mistake.

Change the line 12 from
public String getCompareResult(String date){
to
public String getCompareResult(String date) throws ParseException{

And this error will disappear. :)

Regards,
   Tomas Helgi
I am very happy very very happy now there is no error after i created this page (nearly after one month)all bcos of
ALL BCOS OF UR VERY VERY VERY KIND  HELP ,can i  compile this jsp page .

Thank you so Much Tomas Heiqi

Thank You
Hi Tomas Helqi

I have doubt how this will intract with my select statement and give only the records wich is > than todays date how should i do that ?

When i compile  it  selects all the  3910 records as by my knowledge only few records is  there
pls  very kindly help me  pls i attached the output also



<%@page import="java.util.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
<%!
public class CompareDates{
public String getCompareResult(String date) throws ParseException{
 DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(date);
 Date d1 = df.parse(date); //error line
 Date today = new Date();
 String relation;
 if (d1.equals(today))
 relation = "the same as date";
  else if(d1.before(today))
   relation = "before";
 	else
 	    relation = "after";
 	  return df.format(d1) + "is" + relation +' '+ df.format(today); 			
 	  
 	  }
 }	
%>
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
//String dateStr ="01-05-2001";
//java.text.SimpleDateFormat dateFormat = new java.util.text/SimpleDateFormat("dd-mm-yyyy")
//java.text.SimpleDateFormat dateFormat = new java.util.text.SimpleDateFormat("dd-mm-yyyy");
//java.util.Date roomdate = dateFormat.parse(dateStr);
//Format frmt = new SimpleDateFormat("dd-mm-yyyy");
//String dt = frmt.format(roomdate);
//String sql = "select DATE(TIMESTAMP(05-05-2001))date from room_booking where TIMESTAMP(05-05-2001)) > CURRENT TIMSTAMP ";
//select DATE(TIMESTAMP(stringdatefield)) mydatefield 
//from room_bookings where TIMESTAMP(stringdatefield)) > CURRENT TIMESTAMP;
 
String sql = "select date,purpose,status,rid from room_booking ";
//String sql = "select [date],purpose,status,rid from room_booking where convert(datetime,Substring([date],5,4)+Substring([date],1,4),112)> getdate()";
//string sql = "select [date],purpose,status,rid from room_booking where convert (datttime ,Substring ())"
 
ResultSet rs = stmt.executeQuery(sql);
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("date");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	rid = rs.getInt("rid");
 
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
 
    records.addElement(bean);     
    
    }
     
 %>
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>

Open in new window

booki.doc
Hi Tomas Helqi
Now  the problem is it is giving the same result before the new patch is included, can you pls advice me in solving the problem and help me in get the value  > than today

Kindly help me thank You so much

With thnaks
JeevanJosh

      Hi!

I modified the code a little bit. This should work as expected.
However this solution takes all the data from the database and then filters out the desired results.
If the data is only 3910 records then this would not be any burden to the web-application server. :)
However the best way is to have the data filtered out in the database before it is handed over to the web-application and that you do in the SQL statement as I mentioned in the first post. :)

Regards,
    Tomas Helgi
<%@page import="java.util.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
<%!
public class CompareDates{
public String getCompareResult(String date) throws ParseException{
 DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(date);
 Date d1 = df.parse(date); //error line
 Date today = new Date();
 String relation;
 if (d1.equals(today))
 relation = "the same as date";
  else if(d1.before(today))
   relation = "before";
 	else
 	    relation = "after";
 	  return df.format(d1) + "is" + relation +' '+ df.format(today); 			
 	  
 	  }
public Integer getCompareResult(String thedate) throws ParseException{
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = df.parse(thedate); 
 	Date today = new Date();
 	Integer relation;
 	if (d1.equals(today))
 	    relation = 0;
 	else if(d1.before(today))
 	    relation = -1;
 	else
 	    relation = 1;
 	return relation; 				
	
  }
 
 }	
 
 
%>
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
//String dateStr ="01-05-2001";
//java.text.SimpleDateFormat dateFormat = new java.util.text/SimpleDateFormat("dd-mm-yyyy")
//java.text.SimpleDateFormat dateFormat = new java.util.text.SimpleDateFormat("dd-mm-yyyy");
//java.util.Date roomdate = dateFormat.parse(dateStr);
//Format frmt = new SimpleDateFormat("dd-mm-yyyy");
//String dt = frmt.format(roomdate);
//String sql = "select DATE(TIMESTAMP(05-05-2001))date from room_booking where TIMESTAMP(05-05-2001)) > CURRENT TIMSTAMP ";
//select DATE(TIMESTAMP(stringdatefield)) mydatefield 
//from room_bookings where TIMESTAMP(stringdatefield)) > CURRENT TIMESTAMP;
 
String sql = "select date,purpose,status,rid from room_booking ";
//String sql = "select [date],purpose,status,rid from room_booking where convert(datetime,Substring([date],5,4)+Substring([date],1,4),112)> getdate()";
//string sql = "select [date],purpose,status,rid from room_booking where convert (datttime ,Substring ())"
 
ResultSet rs = stmt.executeQuery(sql);
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("date");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	rid = rs.getInt("rid");
CompareDates.getCompareResult
         if(CompareDates.getCompareResult(date)>0){ 
          // we are only adding to the records if date > today
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
         records.addElement(bean);     
         }   
    }
     
 %>
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>

Open in new window

Hi Tomas Helqi

Thank You so much for the very kind help & understanding my problem and answering according to me need ,thank you so much, afer i modified according to the coding wich is given i have some errors

error 1: JavaCompile :Duplicate method getCompareResult in type CompareDates
error 2: javaCompile:Typemismatch:cannot covert from int to Integer
error3: javaCompile:Syntax error on keyword "if","*=","%=","+=",">>=","<<=",">>>=","&&;=","^=","!=","++","--", expected.

can u kindly pls expalin why we r inculding this part
when i change getComapreResult as getComapreResult1 the error1 is diappear but i am sure what i am doing is wrong

can u pls kindly expalin to me
thnak you so much for all the understanding and ur very kind help

[public Integer getCompareResult(String thedate) throws ParseException{
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = df.parse(thedate);
       Date today = new Date();
       Integer relation;
       if (d1.equals(today))
             relation = 0;
       else if(d1.before(today))
             relation = -1;
       else
             relation = 1;

       return relation;
 ]      


with lots of thanks
Jeevanjosh


%@page import="java.util.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
<%!
public class CompareDates{
public String getCompareResult(String date) throws ParseException{
 DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(date);
 Date d1 = df.parse(date); //error line
 Date today = new Date();
 String relation;
 if (d1.equals(today))
 relation = "the same as date";
  else if(d1.before(today))
   relation = "before";
 	else
 	    relation = "after";
 	  return df.format(d1) + "is" + relation +' '+ df.format(today); 			
 	  
 	  }
public Integer getCompareResult(String thedate) throws ParseException{
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = df.parse(thedate); 
 	Date today = new Date();
 	Integer relation;
 	if (d1.equals(today))
 		relation = 0;
 	else if(d1.before(today))
 		relation = -1;
 	else
 		relation = 1;
 
 	return relation;
 	
 	
  }
 
 }	
 %>
 
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
//String dateStr ="01-05-2001";
//java.text.SimpleDateFormat dateFormat = new java.util.text/SimpleDateFormat("dd-mm-yyyy")
//java.text.SimpleDateFormat dateFormat = new java.util.text.SimpleDateFormat("dd-mm-yyyy");
//java.util.Date roomdate = dateFormat.parse(dateStr);
//Format frmt = new SimpleDateFormat("dd-mm-yyyy");
//String dt = frmt.format(roomdate);
//String sql = "select DATE(TIMESTAMP(05-05-2001))date from room_booking where TIMESTAMP(05-05-2001)) > CURRENT TIMSTAMP ";
//select DATE(TIMESTAMP(stringdatefield)) mydatefield 
//from room_bookings where TIMESTAMP(stringdatefield)) > CURRENT TIMESTAMP;
 
String sql = "select date,purpose,status,rid from room_booking ";
//String sql = "select [date],purpose,status,rid from room_booking where convert(datetime,Substring([date],5,4)+Substring([date],1,4),112)> getdate()";
//string sql = "select [date],purpose,status,rid from room_booking where convert (datttime ,Substring ())"
 
ResultSet rs = stmt.executeQuery(sql);
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("date");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	rid = rs.getInt("rid");
CompareDates.getCompareResult
         if(CompareDates.getCompareResult(date)>0){ 
          // we are only adding to the records if date > today
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
         records.addElement(bean);     
         }   
    }
     
 %>
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>

Open in new window

Syntaxerror.doc
Hi Toams Helqi
 I am  very  waiting for ur kind reply, waring is given for me to complete this,kindly help me to solve the problem.
waiting for the reply, thank you so much

With lots of thanks
jeevanjosh



Hi Toams Helqi
 
 pls  very kindly help me to solve the  problem,waiting for ur kind reply.

with Lots& Lots of thanks
jeevanjosh


Change line 32 to
public Integer getCompareResult1(String thedate) throws ParseException
to
public int getCompareResult1(String thedate) throws ParseException

Regards,
    Tomas Helgi

Hi Tomas Helqi
 Thank you so much for hte reply, i am having error 1,& error 2 , kindly  help me inthis

With thanks
JeevanJosh
error2.doc

Sorry i made mistake  replaced Int  by int, now i am having only
error 2:in line 38,40,42,43 and
error 3 :in line 89

[
error 2: javaCompile:Typemismatch:cannot covert from int to Integer
error3: javaCompile:Syntax error on keyword "if","*=","%=","+=",">>=","<<=",">>>=","&&;=","^=","!=","++","--", expected.
]

Sorry for the mistake tha i have done kindly help in solving the other  errors,pls

With thanks
Jeevanjosh

change also line 36
      Integer relation;
to
      int relation;


Regards,
    Tomas Helgi
Remove the line 89 or comment it out.

Regards,
   Tomas Helgi
Thank You,Thank you so much, now only having error 3 ,pls kindly help
error 3 in line89

Thank You so much

See my last comment ;)

Regards,
   Tomas Helgi
If i comment line 91 is giving error as syntax error ontoken"bean" ;expected
if i put ; on line 88 In valid expression
attached my errors
Doc12.doc
The error you are getting now is because you commented out wrong line

CompareDates.getCompareResult   <<< This line should be commented out or removed
         if(CompareDates.getCompareResult(date)>0){      <<< not this one


Regards,
   Tomas Helgi
Is it working now  ?

Regards,
   Tomas Helgi
Hi Tomas Helqi

Thank you somuch for the kind reply,
if i comment this line CompareDates.getCompareResult   the error is  occuring in the next line( [f(CompareDates.getCompareResult(date)>0){ )]

the error is : JavaCompile :the method get ComapreResult(String) from the type bookings_jsp_0.ComapreDates is not Static

Pls kindly help me to solve the problem i waiting for ur reply

Thank you so much
with thanks
Jeevanjosh


error5.doc
Sorry  Tomas helgi
 I made some mistake in the line 37 i didn't opend the'(' so,afer i  corrected that it is ,now it is giving some other error
inthe line [   if(CompareDates.getCompareResult(date)>0){      ]

error : JavaCompile :the operator > is undefined for the argument type(s) String ,int

kindly help me in solving this error
waiting for ur reply
With Lots of thanks
Jeevanjosh
error5.doc
Hi Toams Helgi

Pls kindly help to solve the problem,waiting for ur kind  reply.

Thank you
Hi Tomas helgi

 pls kindly reply waiting for the reply

with thanks
jeevanjosh
   Hi!

Change the line
   if(CompareDates.getCompareResult(date)>0){      
to
   if(CompareDates.getCompareResult1(date)>0){      

Regards,
   Tomas Helgi
Hi  Toams helqi
Thank you so much for the kind reply
it is giving the following error on the same line
JavaCompile :the method get ComapreResult(String) from the type booking_jsp_0.ComapreDates is not Static

with thanks you
jeevanjosh


Doc6.doc
Then put the keyword static in the line where the function is defined like this

public static int getCompareResult(String thedate) throws ParseException{


Regards,
   Tomas Helgi

Again it gives error

The Method getCompareResult cannot be declared static,satic method can only be declared in static or top level type

with thanks
jeavanjosh
Doc7.doc
Sorry about that I should have noticed it. :)
The whole class should be declared static so change the line
    public class CompareDates{
to
    public static class CompareDates{

And change the functions to
public String getCompareResult(String thedate) throws ParseException
and
public int getCompareResult1(String thedate) throws ParseException


Regards,
   Tomas Helgi
Hi Toams Helgi

Now i am not geting any error, i changed
public int getCompareResult1(String thedate) throws ParseException
into
public static int getCompareResult(String thedate) throws ParseException s this is correct?

1.then when i run the compile and run the file it is not giving any  result
2. how to write this public class in my util.java bcos my superior impose me to write  the public class in the util.java how to write this  the public class in util.java and call in the jsp
my superior says i should not write my public class file in the jsp,
pls kindly help in this  thank you

Thank You somuch

kindly help




utiljava.txt
bookingss.txt
seeking ur help to solve this problem

Thank You so much
Hi Tomas helgi

waiting for the kind reply form you

reagards
jeevanjosh
Just copy the class to the package eform.util
and delete it from the jsp then add a
<%@page import="eform.util.*"%>
to the jsp page and that should be it.
Regarding the no results then make sure for testing that you have some bookings (test data) that should fall into the required spec.

Regards,
   Tomas Helgi
Hi Tomashelgi

Thank you for the kind reply , placed  my public class file in the util.java ,solved the errors,
and trying to upload the file in the devlopment side, and to chec the output ,when i am doing that i am not able to view the web page.
this  statement is  (if(CompareDates.getCompareResult(date)>0){    )
changed into (if(eform.util.Util.getComapreResult(date)>0){

then also it is giving error website cannot be dispaly
kindly help me in this  problem is there is any date format error? means where it is pls kindly point out
the mistakes for me,attached my bookings.jsp,and Util.java

With lots of thanks
jeevanjosh




bookingss.txt
JUtil.txt
Hi Tomas helgi

waiting for the reply ,kindly pls reply thank you,

with thanks
jeevanjosh
   Hi

Put a try-catch block around the code you want to debug in the JSP
http://www.java2s.com/Code/Java/JSP/UsingatrycatchBlock.htm
That way your error will be displayed on the web-page.

Regards,
   Tomas Helgi

Hi Tomas  helqi
 can pls guide me in that ,pls i could't understand,kindly


Thank you
jeevanjosh
%@page import="java.util.*"%>
<%@page import="eform.util.Util"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
String sql = "select date,purpose,status,rid from room_booking";
//String sql = "select date,purpose,status,rid from room_booking where status = 'Taken'";
//String sql = "select [date],purpose,status,rid from room_booking where convert(datetime,Substring([date],5,4)+Substring([date],1,4),112)> getdate()";
//string sql = "select [date],purpose,status,rid from room_booking where convert (datttime ,Substring ())"
 
ResultSet rs = stmt.executeQuery(sql);
 
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
//if(eform.util.Util.getCompareResult1(date)>0){
 
	date = rs.getString("date");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	rid = rs.getInt("rid");
	
 
if(eform.util.Util.getCompareResult1(date)>0){
 
//if(util.getCompareResult1(date)>0){ //Error in this line
 
 
     //we are only adding to the records if date > today
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
         records.addElement(bean);     
         }   
   }
 
 %>
 
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>
 

Open in new window

Like this :)
These classess have to also be included in the eform package
import="java.util.Calendar";
import="java.util.Date";
import="java.text.*;
import="java.text.DateFormat";
import="java.text.ParseException";
import="java.text.SimpleDateFormat";

Regards,
   Tomas Helgi
%@page import="java.util.*"%>
<%@page import="eform.util.Util"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
 
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
String sql = "select date,purpose,status,rid from room_booking";
//String sql = "select date,purpose,status,rid from room_booking where status = 'Taken'";
//String sql = "select [date],purpose,status,rid from room_booking where convert(datetime,Substring([date],5,4)+Substring([date],1,4),112)> getdate()";
//string sql = "select [date],purpose,status,rid from room_booking where convert (datttime ,Substring ())"
 
ResultSet rs = stmt.executeQuery(sql);
 
 
	String date;
    String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
 
//if(eform.util.Util.getCompareResult1(date)>0){
 
	date = rs.getString("date");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	rid = rs.getInt("rid");
	
 try{
if(eform.util.Util.getCompareResult1(date)>0){
 
//if(util.getCompareResult1(date)>0){ //Error in this line
 
 
     //we are only adding to the records if date > today
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
         records.addElement(bean);     
         }catch(Excepction e){
         out.println("An exception occurred: " + e.getMessage());
        }
   }
 
 %>
 
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
 
<table>
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>

Open in new window

included the classes n the eform package
Hi Tomas hegi

i  included  and how i trace the error ,need ur help
with thanks
jeevanjosh



Waiting for ur reply

thank you
The codesnippet I included should be enough.
What I did is I putted try-catch block around the if-statement block to catch the error and
display the error on the webpage.
Adding this line e.printStackTrace() inside like this

}catch(Excepction e){
         out.println("An exception occurred: " + e.getMessage());
         out.println(e.printStackTrace());
}

will also print out to the webpage the stackTrace of the error.

Regards,
   Tomas Helgi



It gives the following error

Error line :the method println() in the type printStream is not applicable for the argument(void)

	
	//public static class CompareDates{
	public String getCompareResult(String date) throws ParseException {
		
	 DateFormat df = new SimpleDateFormat("yyyy-MM-dd");//error line1
	 System.out.println(date);
	 Date d1 = df.parse(date); 
	 Date today = new Date();
	 String relation;
	 if (d1.equals(today))
	 relation = "the same as date";
	  else if(d1.before(today))
	   relation = "before";
		else
			relation = "after";
		  return df.format(d1) + "is" + relation +' '+ df.format(today); 			
 	  
	
	}
	
	public static int getCompareResult1(String date) throws ParseException{
		try{
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");//same error as line1
	Date d1 = df.parse(date); 
	Date today = new Date();
		  int relation;
		if (d1.equals(today))
			relation = 0;
		else if(d1.before(today))
			relation = 1;
		else
			relation = -1;
		return relation; 		
		
	 		}catch(Exception e){
		System.out.println("An exception occurred: " + e.getMessage());
		System.out.println(e.printStackTrace());// error line
}
 
	}	

Open in new window

error.doc
waiting pls reply ,pls
My mistake
e.printStackTrace()
instead of
System.out.println(e.printStackTrace());

and you have to look into the logfile of the Application Server or the System.out window of your IDE
to see the stackTrace.
NOTE!
Also if you look at the code-snippet i posted (ID:21149126) I putted the try-catch block in the JSP not the util package because the functions that we created there throw ParseExceptions which we can catch in the JSP or other classes/functions.


Regards,
   Tomas Helgi
Hi Tomas helqi

 when i try the  filter condition when i
1 try{
if(eform.util.Util.getCompareResult1(date)>0){ --- the give alll result (3911)
if(eform.util.Util.getCompareResult1(date)<1){ -----all records
if(eform.util.Util.getCompareResult1(date)>1){ ----- all records
if(eform.util.Util.getCompareResult1(date)<0){ ----- all records
if(eform.util.Util.getCompareResult1(date)>-1){ ----- all  records



if(eform.util.Util.getCompareResult1(date)<0){ ----- no records
if(eform.util.Util.getCompareResult1(date)<-1){ ----- no records
if(eform.util.Util.getCompareResult1(date)<0){ ----- no records

i attached my logfile
 kindly help me in solving this problem'
with thanks
jeevanjosh

errerlog.doc
Hi Tomas helgi

when i change the Date format into ("dd/MM/YYYY")
 when i try the  filter condition when i
1 try{
if(eform.util.Util.getCompareResult1(date)>0){ --- the give alll result (3911)
if(eform.util.Util.getCompareResult1(date)<1){ -----all records
if(eform.util.Util.getCompareResult1(date)>1){ ----- all records
if(eform.util.Util.getCompareResult1(date)<0){ ----- all records
if(eform.util.Util.getCompareResult1(date)>-1){ ----- all  records



if(eform.util.Util.getCompareResult1(date)<0){ ----- no records
if(eform.util.Util.getCompareResult1(date)<-1){ ----- no records
if(eform.util.Util.getCompareResult1(date)<0){ ----- no records

2.wheni change the format into ("dd-MM-YYYY")
the  output if(eform.util.Util.getCompareResult1(date)>0){  ------no records
3. when i change the formate int ("ddmmyyyy")
then
if(eform.util.Util.getCompareResult1(date)>0){ ------ no records
 my table as the value in the form of dd/mm/yyyy in string
pls kindly help me in solving the problem

with thanks
jeevanjsoh
Hi Tomas helgi

waiting for ur reply pls
jeevanjosh
Make sure that the dateformat in the compare-function is the same as the dateformat stored in the database.

Regards,
   Tomas Helgi
Hi tomas
It is in the format of dd/mm/yyyy in the string

what  i have  to do now
thank you
jeevanjosh
Doc4.doc
Hi Tomas Hegi

what is the command to view the table structure after i connected tothe data base

Thank you
jeevan josh

Hi Tomas hegi

How can i come out the screen (attached) what is the command (ater i trace err)

with thanks
jeevanjosh
Doc2.doc
kindly reply

thank you
Hmmmm

In the eform.util.Util.getCompareResult1 function we have an SimpleDateFormat object called df.
Instead of
DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
put these lines
DateFormat df = new SimpleDateFormat("dd/mm/yyyy", Locale.getDefault());
df.setLenient ( false );

Regards,
  Tomas Helgi
sorry i fund out the format of the date inthe database
dd/mm/yyyy,
now   after i changed into
try{
if(eform.util.Util.getCompareResult1(date)>0){
//System.out.println("check1");
   //we are only adding to the records if date > today
      JoRoomBookingBean bean = new JoRoomBookingBean();
 
 //System.out.println("check2");
      bean.setDate(date);
      bean.setPurpose(purpose);
      bean.setStatus(status);
      bean.setRid(rid);
       records.addElement(bean);
    }  
    }catch(Exception e){
    System.out.println("An exception occured :"+e.getMessage());
     e.printStackTrace();
   }    
   
   //System.out.println("Joshline test here");
}

 %>

i am getting the all hte values of the table (3911)records

kindly help in solving the problem
with thanks
jeevanjosh

	
	//public static class CompareDates{
	public String getCompareResult(String date) throws ParseException {
		
	 DateFormat df = new SimpleDateFormat("dd/mm/yyyy");//error line1
	 System.out.println(date);
	 Date d1 = df.parse(date); 
	 Date today = new Date();
	 String relation;
	 if (d1.equals(today))
	 relation = "the same as date";
	  else if(d1.before(today))
	   relation = "before";
		else
			relation = "after";
		  return df.format(d1) + "is" + relation +' '+ df.format(today); 			
 	  
	}
	
	
	public static int getCompareResult1(String date) throws ParseException{
			
	DateFormat df = new SimpleDateFormat("dd/mm/yyyy");//same error as line1
	Date d1 = df.parse(date); 
	Date today = new Date();
		  int relation;
		  if (d1.equals(today))
			relation = 0;
		else if(d1.before(today))
			relation = 1;
		else
			relation = -1;
			return relation;
	//return relation
 		
	}

Open in new window

Hi Tomas Helgi

Thnak you  so much for the very kind help,
 i  changed into

DateFormat df = new SimpleDateFormat("dd/mm/yyyy", Locale.getDefault());
      df.setLenient ( false );
But give all the records of the table (attached my out put)

kindly kindly pls help me
jeevanjosh


Doc7.doc
    Hi

I changed the getCompareResult1 function a little bit (see below)

Regards,
   Tomas Helgi
public static int getCompareResult1(String date) throws ParseException{		
	DateFormat df = new SimpleDateFormat("dd/mm/yyyy", Locale.getDefault());
         df.setLenient ( false );
	Date d1 = df.parse(date); 
	Date today = new Date();
         int relation;
	if (d1.equals(today))
	   relation = 0;
	else if(d1.before(today))
	   relation = -1;
	else
	   relation = 1;
	return relation; 		
}

Open in new window

If you have moved the functions to the Util package then I suggest deleting it from the bookings JSP so it won't confuse you or other programmers. :)

Regards,
   Tomas Helgi
hi Tomas Hegi
 
It gives the same value 3911 reords

help mee.. pls
Thank You
jeevanjosh
//public static class CompareDates{
	public String getCompareResult(String date) throws ParseException {
		
	 DateFormat df = new SimpleDateFormat("dd/mm/yyyy");//error line1
	 System.out.println(date);
	 Date d1 = df.parse(date); 
	 Date today = new Date();
	 String relation;
	 if (d1.equals(today))
	 relation = "the same as date";
	  else if(d1.before(today))
	   relation = "before";
		else
			relation = "after";
		  return df.format(d1) + "is" + relation +' '+ df.format(today); 			
 	  
	}
	
	
	public static int getCompareResult1(String date) throws ParseException{
			
	//DateFormat df = new SimpleDateFormat("dd/mm/yyyy");//same error as line1
	DateFormat df = new SimpleDateFormat("dd/mm/yyyy", Locale.getDefault());
		df.setLenient ( false );
	
	Date d1 = df.parse(date); 
	Date today = new Date();
		  int relation;
		  if (d1.equals(today))
			relation = 0;
		else if(d1.before(today))
			relation = 1;
		else
			relation = -1;
			return relation;
	//return relation
 		
	}

Open in new window

waiting for ur kindreply

with thanks
jeevanjosh
exchange ALL the code I posted in the last comment in the Util package.

Regards,
   Tomas Helgi
i am very Sorry, for the mistake i  made
i exchange the entire code now it is giving 0 records as a result

waiting .................
thank you
jeevanjosh


	
//	public static int getCompareResult1(String date) throws ParseException{
			
	//DateFormat df = new SimpleDateFormat("dd/mm/yyyy");//same error as line1
	public static int getCompareResult1(String date) throws ParseException{		
	DateFormat df = new SimpleDateFormat("dd/mm/yyyy", Locale.getDefault());
		 df.setLenient ( false );
	Date d1 = df.parse(date); 
	Date today = new Date();
		 int relation;
	if (d1.equals(today))
	   relation = 0;
	else if(d1.before(today))
	   relation = -1;
	else
	   relation = 1;
	return relation; 		
}

Open in new window

Hi Tomas helgi

i attached my logfile
kindly help in this  after i used ur last correction

Thank you
jeevanjosh
Doc9.doc
Hi Tomas heqi
waiting for ur kind reply
sorry to give you trouble
waitng for ur result
Hi Tomas helgi
HAPPY EASTER!

Thank You
regards
jeevanjosh
(no attachment !!!!)
What database are you using ?

Regards,
   Tomas Helgi
If you are using DB2 then open a connection to the database in some database query tool.
and execute

select date,purpose,status,rid
from room_booking
where DATE(date) > DATE(CURRENT TIMESTAMP)

How many results will that give you ?

Regards,
   Tomas Helgi
Hi tomas hegi
Thank you so much for the kind reply ,after i  changed, alos it gives the same error,

Web page can't be dispalyed.

Thank you
kindly help
regards
Joshline


Doc7.doc
Hi Tomashegi
  we are using db2 ,with  when i changed my sql statement , i amgetting the same error as
Web page cant be dispalyed,
i attached logfile ,traceErr.traceOut,& error output

kindly help in solving the problem

with thanks
Jeevanjosh



<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
String sql = "select date,purpose,status,rid from room_booking where DATE(date) > DATE(CURRENT TIMESTAMP)";
//String sql = "select date,purpose,status,rid from room_booking";
 
ResultSet rs = stmt.executeQuery(sql);
	String date;
	String purpose;
	String status;
	int rid;
 
	Vector records = new Vector();
	while (rs.next()){
	 
	date = rs.getString("date");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	rid = rs.getInt("rid");
 
try{
if(eform.util.Util.getCompareResult1(date)>0){
 
//if(eform.util.Util.getCompareResult1(date)>0){
	//we are only adding to the records if date > today
		
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setRid(rid);
	records.addElement(bean);
	}  
   
    }catch(Exception e){
    System.out.println("An exception occured :"+e.getMessage());
     e.printStackTrace();
   }    
   
   	//System.out.println("Joshline test here");
}
 
 %>
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
<table>
 
	<tr bgcolor="CCFFFFF">
		<td>date</td>
		<td>purpose</td>
		<td>status</td>
		<td>rid</td>
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFFFCC">
		<td><%=bean.getDate()%></td>
		<td><%=bean.getPurpose()%></td>
		<td><%=bean.getStatus()%></td>
		<td><%=bean.getRid()%></td>
    </tr>
    
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>
 

Open in new window

tel.doc
error12.doc
Hi Tomas Helgi

 Thank You so much for the kind help in soving this problem, now the r esult are comming, thankyou so for the hellp,all ur anwers are according the  my  need perfectly , thank you so much  it  is very very excellent & and very patiently you answered my question, its rly surprise me  , you answered me all the question i have asked, its rly greate.

your answers are very very excellent
Thank you once again
Thank you so much, thanks a lot

with million thanks
jeevanjosh
ans.doc
Hello Tomas helgi

i have to ask some other question related to this
how can i grade this  session
 thank you
with regards
jeevanjosh
hi Toams Helgi

 i have three tables room_booking,room,time_slot
i am taking  the Pk for room_booking is RID(room ID)  table room is having (RID)
 and room_booking (RBID) ,time_slot(RBID) , i want to connect all the three table when i connect  the two table it is giving value  when i connect the 3rd table it is giving error.
as attached kindly help in solving this problem

With thanks
jeevanjosh


<%@page import="java.util.*"%>
<%@page import="eform.util.Util"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
 
//String sql = "select date,purpose,status,rid from room_booking where DATE(date) > DATE(CURRENT TIMESTAMP)";
//String sql = "select date,purpose,status,rid from room_booking";
String sql = "select a.date,b.name,a.purpose,a.status,a.emid,a.rid,c.rbid from room_booking a,room b,time_slot c where a.rid = b.rid or a.rbid = c.rbid and status = 'Taken'";
 
ResultSet rs = stmt.executeQuery(sql);
	String date; 
 	String name;
	String purpose;
	String status;
	String emid;
//	String time;
	int rid;
	int rbid;
	
 
 
	Vector records = new Vector();
	while (rs.next()){
	 
	date = rs.getString("date");
	name = rs.getString("name");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	emid = rs.getString("emid");
//	time = rs.getString("time");
	rid = rs.getInt("rid");
	rbid = rs.getInt("rbid");
		
	
try{
if(eform.util.Util.getCompareResult1(date)>0){
 
//if(eform.util.Util.getCompareResult1(date)>0){
	//we are only adding to the records if date > today
		
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
	bean.setDate(date);
	bean.setName(name);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setEmid(emid);
//	bean.setTime(time);
	bean.setRid(rid);
	bean.setRid(rbid);
 
	records.addElement(bean);
	}  
   
    }catch(Exception e){
    System.out.println("An exception occured :"+e.getMessage());
    e.printStackTrace();
   }    
   
   	//System.out.println("Joshline test here");
}
 
 %>
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
<table>
 
	<tr bgcolor="CCFFFCC">
		<td>date</td>
	     <td>name</td>
		<td>purpose</td>
		<td>status</td>
		<td>emid</td>
 
		<td>rid</td>
		<td>rbid</td>
		
		
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFCCCC">
		<td><%=bean.getDate()%></td>
        <td><%=bean.getName()%></td>
		<td><%=bean.getPurpose()%></td>
  		<td><%=bean.getStatus()%></td>
  		<td><%=bean.getEmid()%></td>
 
		<td><%=bean.getRid()%></td>
		<td><%=bean.getRbid()%></td>
		
	  
	    		
    </tr>
    
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>
 

Open in new window

Doc10.doc
kindly waiting for ur answer

thank you
regards
jeevanjosh
Hi Toams helqi

Are you in leave ,i want to ask some clear some more  doubt ,kindly pls reply,waiting for the reply,
thank you.

Thank You so much
with thanks
Jeevanjosh
Hi tomashelgi

Thnak you  so much for  all the great answers from your side, i am able to get the answers wich is > than today,
now one mor requirement , is to get the values =  to today,
what  i done is i converted  this below line in to
try{
if(eform.util.Util.getCompareResult1(date)>0){

INTO
try{
if(eform.util.Util.getCompareResult1(date)==0){

is it correct i am not sure,when i run the file it gives no result but i have three records equal to today
26/03/2008 i attached my files


kindly help me in solving this problem
its bcos of your kind help i can  reach up to this level
thank you so much
waiting for ur reply
with thanks
jeevanjosh


Util.java
 
	public String getCompareResult(String date) throws ParseException {
	 DateFormat df = new SimpleDateFormat("dd/MM/yyyy");//error line1
	 System.out.println(date);
	 Date d1 = df.parse(date); 
	 Date today = new Date();
	 String relation;
	 if (d1.equals(today))
	 relation = "the same as date";
	  else if(d1.before(today))
	   relation = "before";
		else
			relation = "after";
	  return df.format(d1) + "is" + relation +' '+ df.format(today); 			
	}
 
//	public static int getCompareResult1(String date) throws ParseException{
	//DateFormat df = new SimpleDateFormat("dd/mm/yyyy");//same error as line1
	
		
	public static int getCompareResult1(String date) throws ParseException{		
	DateFormat df = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
			 df.setLenient ( false );
				  
	Date d1 = df.parse(date); 
	Date today = new Date();
		 int relation;
	if (d1.equals(today))
	   relation = 0;
	else if(d1.before(today))
	 relation = -1;
    else
	 relation = 1;
	return relation;
}

Open in new window

bookingss.txt
output1.doc
     Hi!

Yes that is correct if you want to find dates that equals today you use == .
I was on easter holiday.

Regards,
  Tomas Helgi
Hi Tomas helgi

Thank you its very nice  ur back,
i changed into == but  it is giving Zero result,but i have some 3 records for today
but i am not able to get the answers

i attached my output, jsp ,util.java with this
output in sammp.doc
existing todays records in output1.doc



with thnaks
jeevanjosh





<%@page import="java.util.*"%>
<%@page import="eform.util.Util"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
 
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
//String sql = "select date,purpose,status,rid from room_booking where DATE(date) > DATE(CURRENT TIMESTAMP)";
//String sql = "select a.date,b.time,b.rbid from time_slot from room_booking a,time_slot b where a.rbid = b.rbid ";
String sql = "select a.date,b.name,a.purpose,a.status,a.emid,c.time from room_booking a, room b, time_slot c where a.rid = b.rid and a.rbid=c.rbid and status = 'Taken'";
 
ResultSet rs = stmt.executeQuery(sql);
String date; 
 	String name;
	String purpose;
	String status;
	String emid;
	//int rid;
	String time;
 
	Vector records = new Vector();
	while (rs.next()){
	 
	date = rs.getString("date");
	name = rs.getString("name");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	emid = rs.getString("emid");
	//rid = rs.getInt("rid");
	time = rs.getString("time");
	
		
	
try{
if(eform.util.Util.getCompareResult1(date)==0){
//we are only adding to the records if date > today
		
	JoRoomBookingBean bean = new JoRoomBookingBean();
 
 
	bean.setDate(date);
	bean.setName(name);
	bean.setPurpose(purpose);
	bean.setStatus(status);
	bean.setEmid(emid);
//	bean.setRid(rid);
	bean.setTime(time);
 
	records.addElement(bean);
	}  
   
    }catch(Exception e){
    System.out.println("An exception occured :"+e.getMessage());
    e.printStackTrace();
   }    
   
   	//System.out.println("Joshline test here");
}
 
 %>
 
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
<table>
 
	<tr bgcolor="CCFFFCC">
 
        <td>DATE</td>
        <td>NAME</td>
        <td>PURPOSE</td>
        <td>STATUS</td>
        <td>EMID</td>
     
        <td>TIME</td>
	
			
		
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFCCCC">
	
        <td><%=bean.getDate()%></td>
        <td><%=bean.getName()%></td>
        <td><%=bean.getPurpose()%></td>
        <td><%=bean.getStatus()%></td>
        <td><%=bean.getEmid()%></td>
        <td><%=bean.getTime()%></td>
                    		
    </tr>
    
<%}%>
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>
 

Open in new window

output1.doc
samp.doc
Between lines 52 and 53 put  for debuging purposes
if(date.equals("26/03/2008"){
System.out.println("The date is today " + date);
}

You should get 3 lines.

Regards,
   Tomas Helgi
   Hi!

I modfied the getCompareResult1 function (see code snippet) to make sure that
the format of both dates that are compared are the same.
If the formats are not the same it could lead to wrong comparisions. :(

Regards,
   Tomas Helgi
public static int getCompareResult1(String date) throws ParseException{		
	DateFormat df = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
        df.setLenient ( false );
				  
	Date d1 = df.parse(date); 
	Date today = df.parse(df.format(new Date());
	int relation;
	if (d1.equals(today))
	   relation = 0;
	else if(d1.before(today))
	   relation = -1;
    	else
	   relation = 1;
	return relation;
}

Open in new window

Hi Tomas helgi

Thank you when i check the  table the value of the date or like this
"26/3/2008" (will this be a problem) , in that case how?
 when i save into the system how can i save like 26/03/2008

kindly help me

attached my output of the table

with thanks
jeevanjosh
Doc13.doc
The SimpleDateFormat object does the trick. :)
The format we are using in getCompareResult1 is "dd/mm/yyyy" which means that the format is set to "26/03/2008" however somewhere in the process where you insert/update the records the format is set to "dd/m/yyyy".
This is not an issue as long as you make sure that the date you retrieve from the database and the date you use to compare to (todays date) have the same date-format.

Regards,
  Tomas Helgi
Hi tomas helgi


Thank you for the kind reply , i brief about the scenario
1. i have the form (room booking form attached)wich ask for the the booking date when i select it show in the for of march 2008 after i submmit the form it is storing in the format of 26/3/2008
bcos there is BoonkRoomController.java  it has the

BooKRoomController.java
    public ArrayList getDateList()
    {
        return Util.get12Months();
    }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
inside Util.Java

public static ArrayList get12Months() {
 ArrayList _12MonthsList = new ArrayList();
GregorianCalendar today = new GregorianCalendar();
int i = 0;
 while (i < 13) {
   int month = today.get(Calendar.MONTH);
      String monthString = getMonthString(month);
   _12MonthsList.add(monthString + " , " + today.get(1));
    today.add(2, 1);
     i++;
  }
   return _12MonthsList;
}
getMonthString
public static String getMonthString(int month) {
            String monthString = "January";
            if (month == 1) {
                  monthString = "February";
            } else if (month == 2) {
                  monthString = "March";
            } else if (month ==3) {
                  monthString = "April";
            } else if (month ==4) {
                  monthString = "May";
            } else if (month ==5) {
                  monthString = "June";
            } else if (month == 6) {
                  monthString = "July";
            } else if (month == 7) {
                  monthString = "August";
            } else if (month == 8) {
                  monthString = "September";
            } else if (month == 9) {
                  monthString = "October";
            } else if (month == 10) {
                  monthString = "November";
            } else if (month == 11) {
                  monthString = "December";
            }
            return monthString;
      }

      /**
      This method return the month in int according to input month
      @param month Jannuary stands for 0 December stands for 11
      @return int month in numeric format
      */
      public static int getMonthInt(String month) {
            int monthInt = 0;
            if (month.equalsIgnoreCase("February")) {
                  monthInt = 1;
            } else if (month.equalsIgnoreCase("March")) {
                  monthInt = 2;
            } else if (month.equalsIgnoreCase("April")) {
                  monthInt = 3;
            } else if (month.equalsIgnoreCase("May")) {
                  monthInt = 4;
            } else if (month.equalsIgnoreCase("June")) {
                  monthInt = 5;
            } else if (month.equalsIgnoreCase("July")) {
                  monthInt = 6;
            } else if (month.equalsIgnoreCase("August")) {
                  monthInt = 7;
            } else if (month.equalsIgnoreCase("September")) {
                  monthInt = 8;
            } else if (month.equalsIgnoreCase("October")) {
                  monthInt = 9;
            } else if (month.equalsIgnoreCase("November")) {
                  monthInt = 10;
            } else if (month.equalsIgnoreCase("December")) {
                  monthInt = 11;
            }

return monthInt;
      }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


if i change the monthInt,MonthString ,when i add zero in front  no problem for 1to 7 when i change the 8 & 9
it give error Octal08(digit 8) is out  of range the same for the digit 9

PLS KINDLY HELP ME IN SOLVING THIS PROBLEM, OR HOW CAN I GET THE(the values from jan to sep is in the form of "dd/m/yyyy" but other month in the form of dd/mm/yyyy) how to solve this ?)

kindly help me thank you
with thanks
jeevanjosh

doc1.doc
Hi Tomas Helgi

Waiting for your reply,kindly reply
thank  you
with lots of thanks
jeevanjosh
Hi Tomas helgi

Kindly reply pls, pls help me in solving the above problem
waiting for ur kind reply

with thanks
jeevanjosh
Hi Tomas helgi

when I submit the  form it is get saved for JAN to SEP as (eg 26/4/2008 i.e dd/M/yyyy format) for OCT to DEC it is get saved as (26/10/2008 i.e dd/MM/yyyy format),since it is saved in the format of dd/M?yyyy it is not giving answer when we try to put
try{
if(eform.util.Util.getCompareResult1(date) ==0){

how can i save my date fro JAN to DEC also like (dd/MM/YYYY)format ,kindly help in solving this problem,
pls kindly help me thank you.

Thank You
with lots of thanks
jeevanjosh
doc1-1-.doc
hi toams helgi

waiting for ur very kind reply to solve the above problem

thank you
regards
jeevabnjosh

hi Tomas helgi

pls pls................answer

with thanks
jeevanjosh
    Hi!
As I said before. You can use SimpleDateFormat to convert date to string in a format of your choice and
wice versa (convert string representing a date in a sertain format to a Date object).
It's fairly simple.
http://www.java2s.com/Code/Java/Development-Class/SimpleDateformat.htm
http://www.java2s.com/Code/Java/Development-Class/CompareDates.htm
http://www.java2s.com/Code/Java/Development-Class/DateFormatTest.htm

Regards,
   Tomas Helgi
hi Tomas helgi

i am so sorry i am asking many questions to u ,
the problem here is the screen getting the value in the form of 26 Apirl 2008, when i save it is saved in the form of 26/3/2008, now my problem here how can i save this into 26/04/2008 in my data base
date value is taken from roomBookingBean

RoomBookingBean
package eform.beans;

import eform.business.*;
import java.util.ArrayList;

public class RoomBookingBean
{

    public RoomBookingBean()
    {
    }

    public String getAppDate()
    {
        return roomBooking.getAppDate();
    }

    public ArrayList getBookies()
    {
        return aBookies;
    }

    public TimeSlot getBookingTimeSlot()
    {
        return roomBooking.getTimeSlot();
    }

    public String getDate()
    {
        return roomBooking.getDate();
    }

pls kindly help by coding as you done for me before where and how can i change,kindly pls


Doc4.doc
    Hi!

I'm guessing the methods you posted earlier (ID:21219117Author:JeevanjoshDate:03.27.2008 at 07:01AM GMT )
should show why you get the above error.
You have to talk to your coworkers about the reason why this is coded like this
before you change this because that could lead to some other part of the system
failing to work as it should.

Regards,
    Tomas Helgi
Hi Tomas Helgi

Thank You, i thought that if i changed the 0 to 00 &1 to 01 i can get  the result as (for exp:like 26/04/2008) and not as 26/4/2008 now i am not doing like that
bcos i thought i  am using wrong way to reach the result ,
the problem in consutling with the co-workers is that,me alone in this field.

Is this the correct way?pls kindly help


      public static String getMonthInt(String month) {
       String monthStr = "00";
          
            if (month.equalsIgnoreCase("February")) {
                  monthStr = "01";
            } else if (month.equalsIgnoreCase("March")) {
                  monthStr= "02";
            } else if (month.equalsIgnoreCase("April")) {
                  monthStr="03";
            } else if (month.equalsIgnoreCase("May")) {
                  monthStr = "04";
            } else if (month.equalsIgnoreCase("June")) {
                  monthStr = "05";
            } else if (month.equalsIgnoreCase("July")) {
                  monthStr = "06";
            } else if (month.equalsIgnoreCase("August")) {
                  monthStr = "07";
            } else if (month.equalsIgnoreCase("September")) {
                  monthStr= "08";
            } else if (month.equalsIgnoreCase("October")) {
                  monthStr= "09";
            } else if (month.equalsIgnoreCase("November")) {
                  monthStr = "10";
            } else if (month.equalsIgnoreCase("December")) {
                  monthStr = "11";
            }
            return monthStr;
      }

with lots of thanks
jeevanjosh


Well yes this is partly correct.
The only thing I don't understand is why you have the month number subdracted by one ?  January is the first month of the year ("01"), February the second ("02") and so on.

Regards,
   Tomas Helgi
Hi Tomas helgi

It  is bcos Month of Year in numeric form where Jan is 0 and Dec is 11

and it is usly we rep int month = (today.get(2) + 1); and add 1 with that  .(am i correct)

pls help me to go further and finish
kindly pls help

with lots of thanks
jeevanjosh
I would suggest you implemented another function
similar to getMonthInt(String month) which returns the
correct string representation of the month so that you have correct
string representation of a Date.
In this case this function would add 1 to the month and return a string of that value.

Something like

String getMonthIntForDate(String month){
    // as we know that Jan=0 ... Dec=11 then we only ad 1 to the value
    return Integer.parseInt(month)++;
}

Regards,
   Tomas Helgi
Ops sorry I made a mistake.
It should be like this

String getMonthIntForDate(String month){
    // as we know that Jan=0 ... Dec=11 then we only ad 1 to the value
   Formatter fmt = new Formatter();  
    int res = Integer.parseInt(month)++;
    if (res < 10) {
       return  fmt.format("'0'%d", res);
   }else{
       return  fmt.format("%d", res);
   }
}


Regards,
   Tomas Helgi
the Formatter object requires the import of java.util.Formatter
but would automatically be imported if you have java.util.*

Regards,
   Tomas Helgi
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi Tomas helgi

package eform.util;


import java.util.*;
import java.util.GregorianCalendar;
import javax.mail.*;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.text.ParseException;
import eform.database.AbsenteeDB;
import eform.business.Employee;
import java.util.Calendar;
import java.util.Date;
import java.text.*;

public static String getMonthIntForDate(String month){
    // as we know that Jan=0 ... Dec=11 then we only ad 1 to the value
   Formatter fmt = new Formatter();   ///ERROR
  ///when i place the cursor onthe Formatter it gives the error  
//(Formatter cannot be resloved or is not a  type) as  you said  ,there is import java.util.*
    int res = Integer.parseInt(month)++; //ERROR (place the cursor on the redunderline invalid argument to
//operation ++/--)

    if (res < 10) {
       return  fmt.format("'0'%d", res);
   }else{
       return  fmt.format("%d", res);
   }
}
kindly help in solving the  error
thank you so much
jeevanjosh


Hmmm,
Put the line

import java.util.Formatter;

and recompile.

Regards,
   Tomas Helgi
Hi Toams helgi
if i include java.util.(first there is no dropdown option in in the dropdown list),and i try to type and include ,
when i type  like import java.util.Formatter( .Formatter typed)  then it gives  error
The import java.util.Formatter cannot be resolved)

Kindly help in solving the error
 thank you so much
jeevanjosh



Doc10.doc
What version of Java are you using ?
Execute in a cmd : java -version

Regards,
   Tomas Helgi
hi Tomas helgi
  when give the command in the command line
it is giving following(may be i am wrong)

kindly help
Doc11.doc
Sorr yyyy  my mistake Ttomas

I got  the result  java version  "1.4.2_13"
sorry my misatke
Doc11.doc
hmmmm, thats why you cant use Formatter (it's new in version 1.5 :) )
The code below should work fine in version 1.4.2 and above.

Regards,
   Tomas Helgi
public static String getMonthIntForDate(String month){
    // as we know that Jan=0 ... Dec=11 then we only ad 1 to the value      
    int res = Integer.parseInt(month);
    res++;
    
    if (res < 10) {
       return  "0" + Integer.toString(res);
    }else{
       return  Integer.toString(res);
    }
}

Open in new window

Hi  Tomas helgi

Thank you so much ,it rely very kind of you, thank you for helping me in all the problem that i am posting to you, i just copyed the above code and saved my Util.java(there is no error in the Util.java after i copy the new getMonthIntForceDate) and then uploaded into my devlopment side,then i  complie

but it is not changing 4 to 04,(i am i doning any mistake )

kindly help me pls

thnak you somuch
jeevanjosh




Db2-out-put.doc
Hi Tomas Helgi

 waiting for ur kind reply
pls ....  help me in solving the problem

thank you
jeevanjosh
Well how to do you post the data to the database ?
How are you putting together the date before the data is inserted into the db ?

Regards,
   Tomas Helgi
Hi  Tomas

i wiil show the steps in the attach document

Thank you for the kind help
thank you
jeevanjosh
Step-1.doc
Hi Tomas helgi

with the db output
Thank you
jeevanjosh
Step-1.doc
Hmmm,
There are two options.
1) Look at the code on how the month is stored in Step1->Step2. Is it stored int the format "m" or "mm".
    Look how is the date put together in the steps before it is inserted into the db. If the date is a stringfield in the
    table room_booking then most likly the code is putting together a date-string in the format "dd/m/yyyy".
2) Look back at the code of the compare functions (getCompareResults1)  I gave you where we have the
    format "dd/mm/yyyy". Are you absolutly sure that the format of the date in the code line
   date = rs.getString("date");  // (see post ID:21209672Author:JeevanjoshDate:03.26.2008 at 08:20AM GMT)
   is the format "dd/mm/yyyy" not "dd/m/yyyy" ?


Regards,
   Tomas Helgi
hi Tomas helgi
 thank you so much ,even if i change the in the getComapreResult1 in the format of (dd/M/yyyy)  & (dd/MM/yyyy) it sgiving only zero result .
 ans for 1.  there is a method in the Util
/**
      This method return the month in alphabet according to input month
      @param month 1 stands for Jannuary 12 stands for December
      @return String month in alphabet
      */

public static String getMonthString(int month) {
            String monthString = "January";
            if (month == 1) {
                  monthString = "February";
            } else if (month == 2) {
....................
      } else if (month == 11) {
                  monthString = "December";
            }
            return monthString;
      }


this is used for step1,2,3 to represent the month in the form of January,Feburay,,,
when is submitted in the step 4 it is using another mehtod

*/
      public static int getMonthInt(String month) {
            int monthInt = 0;
            if (month.equalsIgnoreCase("February")) {
                  monthInt = 1;
            } else if (month.equalsIgnoreCase("March")) {
                  monthInt = 2;
            } else if (month.equalsIgnoreCase("April")) {
                  monthInt = 3;
            } else if (month.equalsIgnoreCase("May")) {
                  monthInt = 4;
......      
      } else if (month.equalsIgnoreCase("November")) {
                  monthInt = 10;
            } else if (month.equalsIgnoreCase("December")) {
                  monthInt = 11;
            }
            return monthInt;
      }

i hope what i understand from the coding is correct

in step 4 you can see the  RoomConfirmation  under date it is like 03/4/2008
but now my doubt we changed in the new method  
      public static String getMonthIntForDate(String month){ we include "0" infront) but why it is not included inthis step 4444, before it is saved

kindly help me to solve this problem
hope i ans you correctly ...

thank you so much
jeevabjosh



Step-1.doc
Hi Tomas helgi

Thank you so much for all the kind answers u r giving to me, to day also from themorning i am waiting for ur reply.

kindly help me solving this problem
Thank You so much pls ....help........
jeevanjosh


What does the code look like for the date in step 4 ?

Regards,
   Tomas Helgi
Hi Tomas Helgi

so so kind of you , here i attached the jsp wich is calling the step -4  and the BookRoomServelt it is calling

Thank Yo u so much
roomconformation.txt
You should look at the code of the RoomBookingBean to see how it handles the date and returns it through the getDate() function. I believe you find the answer there.

Regards,
    Tomas Helgi
Hi Tomas Helgi

i looked into the RoomBookingBean and
it is like this

package eform.beans;

import eform.business.*;
import java.util.ArrayList;

public class RoomBookingBean
{

    public RoomBookingBean()
    {
    }

    public String getAppDate()
    {
        return roomBooking.getAppDate();
    }

    public ArrayList getBookies()
    {
        return aBookies;
    }

    public TimeSlot getBookingTimeSlot()
    {
        return roomBooking.getTimeSlot();
    }

    public String getDate()
    {
        return roomBooking.getDate();
    }

    public Employee getEmployee()
    {
        return roomBooking.getEmployee();
    }

    public String getName()
    {
        return room.getName();
    }

    public String getPurpose()
    {
        return roomBooking.getPurpose();
    }

    public int getRbid()
    {
        return roomBooking.getRbid();
    }

    public int getRid()
    {
        return room.getRid();
    }

    public Room getRoom()
    {
        return room;
    }

    public RoomBooking getRoomBooking()
    {
        return roomBooking;
    }

    public String getStatus()
    {
        return roomBooking.getStatus();
    }

    public TimeSlot getTakenTimeSlot()
    {
        return room.getTakenTimeSlot();
    }

    public ArrayList getTime()
    {
        return timeSlot.getTime();
    }

    public TimeSlot getTimeSlot()
    {
        return timeSlot;
    }

    public String getType()
    {
        return room.getType();
    }

    public TimeSlot getVacantTimeSlot()
    {
        return room.getVacantTimeSlot();
    }

    public void setAppDate(String appDate)
    {
        roomBooking.setAppDate(appDate);
    }

    public void setBookies(ArrayList aBookies)
    {
        this.aBookies = aBookies;
    }

    public void setBookingTimeSlot(TimeSlot timeSlot)
    {
        roomBooking.setTimeSlot(timeSlot);
    }

    public void setDate(String date)
    {
        roomBooking.setDate(date);
    }

    public void setEmployee(Employee employee)
    {
        roomBooking.setEmployee(employee);
    }

    public void setName(String name)
    {
        room.setName(name);
    }

    public void setPurpose(String purpose)
    {
        roomBooking.setPurpose(purpose);
    }

    public void setRbid(int rbid)
    {
        roomBooking.setRbid(rbid);
    }

    public void setRid(int rid)
    {
        room.setRid(rid);
    }

    public void setRoom(Room room)
    {
        this.room = room;
    }

    public void setRoomBooking(RoomBooking roomBooking)
    {
        this.roomBooking = roomBooking;
    }

    public void setStatus(String status)
    {
        roomBooking.setStatus(status);
    }

    public void setTakenTimeSlot(TimeSlot takenTimeSlot)
    {
        room.setTakenTimeSlot(takenTimeSlot);
    }

    public void setTime(ArrayList time)
    {
        timeSlot.setTime(time);
    }

    public void setTimeSlot(TimeSlot timeSlot)
    {
        this.timeSlot = timeSlot;
    }

    public void setType(String type)
    {
        room.setType(type);
    }

    public void setVacantTimeSlot(TimeSlot vacantTimeSlot)
    {
        room.setVacantTimeSlot(vacantTimeSlot);
    }

    private ArrayList aBookies;
    private Room room;
    private RoomBooking roomBooking;
    private TimeSlot timeSlot;
}

i am not able to trace out  where date is exactly , when i look into RoomBooking it is  with Private String date, i am not able to find out the sloution, the string.class contains all the general methods

Tomas kindly pls help in find out the solution pls

Thank you
with regards
jeevanjosh



RoomBooking.java
 
package eform.business;
 
import java.util.Vector;
 
// Referenced classes of package eform.business:
//            Employee, TimeSlot
 
public class RoomBooking
{
 
    public RoomBooking()
    {
    }
 
    public String checkNullStr(String str)
    {
        if(str == null)
            str = "";
        else
            str = str.trim();
        return str;
    }
 
    public String getAppDate()
    {
        return checkNullStr(appDate);
    }
 
    public String getDate()
    {
        return checkNullStr(date);
    }
 
    public String getEmid()
    {
        return emid;
    }
 
    public Employee getEmployee()
    {
        return employee;
    }
 
    public String getPurpose()
    {
        return checkNullStr(purpose);
    }
 
    public int getRbid()
    {
        return rbid;
    }
 
    public int getRmid()
    {
        return rmid;
    }
 
    public String getRoomName()
    {
        return roomName;
    }
 
    public String getStatus()
    {
        return checkNullStr(status);
    }
 
    public TimeSlot getTimeSlot()
    {
        return timeSlot;
    }
 
    public Vector getVTimeSlot()
    {
        return vTimeSlot;
    }
 
    public void setAppDate(String appDate)
    {
        this.appDate = appDate;
    }
 
    public void setDate(String date)
    {
        this.date = date;
    }
 
    public void setEmid(String emid)
    {
        this.emid = emid;
    }
 
    public void setEmployee(Employee employee)
    {
        this.employee = employee;
    }
 
    public void setPurpose(String purpose)
    {
        this.purpose = purpose;
    }
 
    public void setRbid(int rbid)
    {
        this.rbid = rbid;
    }
 
    public void setRmid(int rmid)
    {
        this.rmid = rmid;
    }
 
    public void setRoomName(String roomName)
    {
        this.roomName = roomName;
    }
 
    public void setStatus(String status)
    {
        this.status = status;
    }
 
    public void setTimeSlot(TimeSlot timeSlot)
    {
        this.timeSlot = timeSlot;
    }
 
    public void setVTimeSlot(Vector vTimeSlot)
    {
        this.vTimeSlot = vTimeSlot;
    }
 
    public String toString()
    {
        return "<br>Name : " + employee.getName() + "<br>ID : " + employee.getEmid() + "<br>" + "<br>Booking Date : " + date + "<br>Application Date : " + appDate + "<br>Purpose : " + purpose;
    }
 
    private String appDate;
    private String date;
    private String emid;
    private Employee employee;
    private String purpose;
    private int rbid;
    private int rmid;
    private String roomName;
    private String status;
    private TimeSlot timeSlot;
    private Vector vTimeSlot;
}

Open in new window

Hi Tomas helgi
there is onemore jsp called room_booking which is changing the day from 0 to 9 as 00 to 09
i attached the jsp pls help me  can this coding help inchanging the month

thankyou
with lots & lots of thanks
jeevanjosh

roombooking.txt
Hi Tomas
the aboveroom_booking  coding is related with the step 2, from here the values are send to data base
kindly help how can i change the vaue of month 0  as 0 ,1 as 01  month and so on,

thank you
so mcuh\
jeevajsh


Step-1.doc
Hi Tomas helgi

waiting for your solution for the above problem , thank you so much ,help..... pls
thank you

jeevanjosh
    Hi!

I looked at the code. I think you should look at this code here.

function openCal()
  {
     window.open('','cal','scrollbars=yes,status=no,width=700,height=400,resizable=yes,left=0,top=25,screenX=0,screenY=25');
        document.calForm.action ="/epublic/calendar/Calendar.jsp";
       document.calForm.target ="cal";
       document.calForm.submit();

  }

as you sent me. See the roombooking.txt ( ID:21294666Author:Jeevanjosh)
This is most likly the source of how the date is formated as the roombooking-beans take the date string "as is".
You should investigate how the calForm's variable cal is cought by the webpage and manipulated.

Regards,
   Tomas Helgi
Hi Tomas Helgi

Thnak You so much fro understanding problem and need and ur helping ne out in solving this problem

Claender .jsp is the  we use for leave purpose i attached that one it is used to fin who r all leave on the particular month

I found out two other methods
1.public static String getTodayStr() {
2.public static String getTodayBooking() {

can  any of theis methods can be used in jsp by calling them? pls help me in this  

bookings.jsp
<%@page import="java.util.*"%>
<%@page import="eform.util.Util"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>

<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");

Connection con = ds.getConnection();
Statement stmt = con.createStatement();

//String sql = "select date,purpose,status,rid from room_booking where DATE(date) > DATE(CURRENT TIMESTAMP)";
//String sql = "select a.date,b.time,b.rbid from time_slot from room_booking a,time_slot b where a.rbid = b.rbid ";
//String sql = "select a.date,b.name,a.purpose,a.status,a.emid,c.time from room_booking a, room b, time_slot c where a.rid = where a.rid = b.rid and a.rbid = c.rbid and status = 'Taken' and orderby date desc";

String sql = "select a.date,b.name,a.purpose,a.status,a.emid,c.time from room_booking a, room b, time_slot c where a.rid = b.rid and a.rbid=c.rbid and status = 'Taken' order by date ";


ResultSet rs = stmt.executeQuery(sql);
    String date;
       String name;
      String purpose;
      String status;
      String emid;
      //int rid;
      String time;

      Vector records = new Vector();
      while (rs.next()){

      date = rs.getString("date");
      name = rs.getString("name");
      purpose = rs.getString("purpose");
      status = rs.getString("status");
      emid = rs.getString("emid");
      //rid = rs.getInt("rid");
      time = rs.getString("time");


try{
//if(eform.util.Util.getCompareResult1(date) > 0 ){
//if(eform.util.Util.getCompareResult1(date ) > 0 ){
if(eform.util.Util.getTodayStr()== date){

//we are only adding to the records if date > today
            
      JoRoomBookingBean bean = new JoRoomBookingBean();
     bean.setDate(date);
     bean.setName(name);
     bean.setPurpose(purpose);
     bean.setStatus(status);
     bean.setEmid(emid);
     bean.setTime(time);
     
     records.addElement(bean);
     
}  
    }catch(Exception e){
    System.out.println("An exception occured :"+e.getMessage());
    e.printStackTrace();
   }    
   
         //System.out.println("Joshline test here");
}

 %>


<head>
<title>ROOM BOOKING LIST</title>

</head>
<body>
<table>

      <tr bgcolor="CFFFCCC">

        <td>DATE</td>
        <td>NAME</td>
        <td>PURPOSE</td>
        <td>STATUS</td>
        <td>EMID</td>
        <td>TIME</td>
      
         </tr>
                
               <%for (int i = 0; i < records.size(); i++) {
          JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
          
         <tr bgcolor="FFFCCCC">
      
        <td><%=bean.getDate()%></td>
        <td><%=bean.getName()%></td>
        <td><%=bean.getPurpose()%></td>
        <td><%=bean.getStatus()%></td>
        <td><%=bean.getEmid()%></td>
        <td><%=bean.getTime()%></td>
    </tr>
   
 
<%}%>
 

</table>
Total Records:
<%=records.size()%>

</body>
</html>
 






calen.doc
Hi TOmas
Sorry for not attach the  Util.java
Util.java

/**
      This method return today date in string day/month/year
      @return String return today date in string day/month/year
      */
      
      public static String getTodayStr() {
            GregorianCalendar today = new GregorianCalendar();
            int dayOfMonth = today.get(5);
            int month = (today.get(2) + 1);
            int year = today.get(1);
            String todayStr = dayOfMonth + "/" + month + "/" + year;
            
            return todayStr;
      }
      /**
      This method return today date in numeric day/month/year
      @return String return today date in numeric day/month/year
      */
      
            
      public static String getTodayBooking() {
            GregorianCalendar today = new GregorianCalendar();
            int dayOfMonth = today.get(5);
            int month = (today.get(2) + 1);
            int year = today.get(1);
            return dayOfMonth + "/" + month + "/" + year;
      }

/**
      This method return today date in string day/month/year
      @return String return today date in string day/month/year
      */
      
      public static String getTodayStr() {
            GregorianCalendar today = new GregorianCalendar();
            int dayOfMonth = today.get(5);
            int month = (today.get(2) + 1);
            int year = today.get(1);
            String todayStr = dayOfMonth + "/" + month + "/" + year;
            
            return todayStr;
      }
      /**
      This method return today date in numeric day/month/year
      @return String return today date in numeric day/month/year
      */
      
            
      public static String getTodayBooking() {
            GregorianCalendar today = new GregorianCalendar();
            int dayOfMonth = today.get(5);
            int month = (today.get(2) + 1);
            int year = today.get(1);
            return dayOfMonth + "/" + month + "/" + year;
      }


pls kindly help is any way i can use the above mehod to get  booking equal to today
thnak  you
jeevanjosh
Find these methods in the code you execute and examine the output string of these methods. :)

Regards,
   Tomas Helgi
hi Tomas hegi

thnak you so much fo the very kind help ,
where  i try  to use Util.java it as the  method of  
/**
      This method return today date in numeric day/month/year
      @return String return today date in numeric day/month/year
      */
      
      public static String getTodayBooking() {
            GregorianCalendar today = new GregorianCalendar();
            int dayOfMonth = today.get(5);
            int month = (today.get(2) + 1);
            int year = today.get(1);
            return dayOfMonth + "/" + month + "/" + year;
      }

and one more method
/**
      This method return today date in string day/month/year
      @return String return today date in string day/month/year
      */
      
      public static String getTodayStr() {
            GregorianCalendar today = new GregorianCalendar();
            int dayOfMonth = today.get(5);
            int month = (today.get(2) + 1);
            int year = today.get(1);
            String todayStr = dayOfMonth + "/" + month + "/" + year;
            
            return todayStr;
      }

3erd method


      /**
      This method return today date in string day/month/year
      @return String return today date in string day/month/year
      */
      
      public static String getTodayStr() {
            GregorianCalendar today = new GregorianCalendar();
            int dayOfMonth = today.get(5);
            int month = (today.get(2) + 1);
            int year = today.get(1);
            String todayStr = dayOfMonth + "/" + month + "/" + year;
            
            return todayStr;
      }
      
      /**
 there is no error in the jsp when i call but it gives the Result as Zero  Records(there is one records  for todays date)


pls   kindly help in solving the problem

thank you
regards
jeevanjosh


<%@page import="java.util.*"%>
<%@page import="eform.util.Util"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%@page import="eform.beans.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.*"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.ParseException"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
 
<%java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/STAFFDBS");
 
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
 
//String sql = "select date,purpose,status,rid from room_booking where DATE(date) > DATE(CURRENT TIMESTAMP)";
//String sql = "select a.date,b.time,b.rbid from time_slot from room_booking a,time_slot b where a.rbid = b.rbid ";
//String sql = "select a.date,b.name,a.purpose,a.status,a.emid,c.time from room_booking a, room b, time_slot c where a.rid = where a.rid = b.rid and a.rbid = c.rbid and status = 'Taken' and orderby date desc";
 
String sql = "select a.date,b.name,a.purpose,a.status,a.emid,c.time from room_booking a, room b, time_slot c where a.rid = b.rid and a.rbid=c.rbid and status = 'Taken' order by date ";
 
 
ResultSet rs = stmt.executeQuery(sql);
    String date; 
 	String name;
	String purpose;
	String status;
	String emid;
	//int rid;
	String time;
 
	Vector records = new Vector();
	while (rs.next()){
 
	date = rs.getString("date");
	name = rs.getString("name");
	purpose = rs.getString("purpose");
	status = rs.getString("status");
	emid = rs.getString("emid");
	//rid = rs.getInt("rid");
	time = rs.getString("time");
 
try{ 
//if(eform.util.Util.getCompareResult1(date) > 0 ){
//if(eform.util.Util.getCompareResult1(date ) > 0 ){
 
//if(eform.util.Util.getToday() == date ){
if(eform.util.Util.getTodayStr()== date){
 
 
//we are only adding to the records if date > today
		
	JoRoomBookingBean bean = new JoRoomBookingBean();
     bean.setDate(date);
     bean.setName(name);
     bean.setPurpose(purpose);
     bean.setStatus(status);
     bean.setEmid(emid);
     bean.setTime(time);
     
     records.addElement(bean);
     
}   
    }catch(Exception e){
    System.out.println("An exception occured :"+e.getMessage());
    e.printStackTrace();
   }    
   
}
 
 %>
 
  	
<head> 
<title>ROOM BOOKING LIST</title>
 
</head>
<body>
<table>
 
	<tr bgcolor="FFFFFFC">
 
        <td>DATE</td>
        <td>NAME</td>
        <td>PURPOSE</td>
        <td>STATUS</td>
        <td>EMID</td>
        <td>TIME</td>
	
   	</tr>
   	        
   		<%for (int i = 0; i < records.size(); i++) {
    	JoRoomBookingBean bean = (JoRoomBookingBean) records.elementAt(i);%>
    	
   	<tr bgcolor="FFFCCCC">
	
        <td><%=bean.getDate()%></td>
        <td><%=bean.getName()%></td>
        <td><%=bean.getPurpose()%></td>
        <td><%=bean.getStatus()%></td>
        <td><%=bean.getEmid()%></td>
        <td><%=bean.getTime()%></td>
    </tr>
    
 
<%}%>
 
 
</table>
Total Records:
<%=records.size()%>
 
</body>
</html>
 

Open in new window

Hi tomas Helgi

According to ur advice after analysing find out as you said  in
 04.03.2008 at 12:51PM EAT, ID: 21270883 the value of the date is stored in the  as Srtdate
from Step -3
i try to convert into monthInt it work out it give result  as the format of 09/04/2008, and 25/05/2008,
suddenly when it is again not giving the correct result.
again it is giving


12room-booking2.txt
hi  tomas helgi

the above txt file is go for the step3,suddenly, when i try to change the value in the like comment the in Util  monthInt it is not  converting  not adding 0 infront of the month, i uncommented that also
can you pls help in comming out this problem
thank you& sorry for giving lots of quries to you
With lot & lot & lots f thanks
jeevanjosh


result.doc
Hi  Tomas Helgi

Thank You so much for all the  very very very kind help you given for me so for,
with  try to modify the existing and inculding in your method ,now i am able to get the date format in the for of "0" added in  front   attached my out put
now  i am able to get the  values wich is greater than today,

even the values are  in the form of dd/MM/YYY  when use


//        public static int getCompareResult1(String date) throws ParseException{
        //DateFormat df = new SimpleDateFormat("dd/mm/yyyy");//same error as line1
      
        public static int getCompareResult1(String date) throws ParseException{            
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
                     df.setLenient ( false );
        
        Date d1 = df.parse(date);
        Date today = new Date();
               int relation;
        if (d1.equals(today))
             relation = 0;
        else if(d1.before(today))
            relation = -1;
        else
         relation = 1;
        return relation;
        }      

pls  very kindly help me how can i  do ,

my heart full of thank for all  the great help you given me through out, with ur kind help i come upto this final level
 
with lots of thanks
jeevanjosh

with reg
            





/**
	This method return the date in "day/month/year" numerically
	@param date "May , 2003" format
	@param day in numeric format
	@return String "day/month/year"
	*/
public static String stringDate(String date, String day) {
 StringTokenizer st = new StringTokenizer(date);
 String month = st.nextToken(" , ");
 String year = st.nextToken();
 int monthInt = getMonthInt(month) + 1;
//  int monthInt = Integer.parseInt(month);
//  monthInt++;
if(monthInt < 10)
	return day + "/" + "0"+monthInt+ "/" + year;
        else
     return day + "/" + monthInt + "/" + year;
		      
	}   	

Open in new window

results.doc
Hi Tomas Helgi

This is  jeevanjosh Thank you so much for all the very kind &  wonderful help ,you answered me more thank 100 questions with lots and lots of kindness ,

thank you so much ,
 i am getting the answer ,

thanks a lot from the , my rel thanks to u Tomas,

thank you so much  it is rely verly great and and kind of you'

thank you once again
 
with lots & lots & lots & lots of thanks
jeevanjosh