The Artima Developer Community
Sponsored Link

Java Answers Forum
URGENT!!! one day left.

2 replies on 1 page. Most recent reply: Sep 23, 2002 11:41 AM by Don Hill

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Jasmine

Posts: 1
Nickname: jcylee
Registered: Sep, 2002

URGENT!!! one day left. Posted: Sep 20, 2002 9:12 PM
Reply to this message Reply
Advertisement
Dear All,

Currently I am working on a Date Time Calcutions. It's suppose to be Current Time (JVm Time) - db_Transaction (UTIME) = lapse (hh:mm:ss)

Becoz of I lead of knowledge on this, spend so much time to research :(
Now, Monday have to do presentation also. Well, anyone who able to help, PLEASE PLEASE PLEASE !!!

Here's my Codes:

<%@page contentType="text/html; charset=iso-8859-1" language="java" import="util.DateUtil" import="java.util.Date" import="java.lang.*" import="java.util.*" import="java.text.*" import="java.sql.*"%>
<%
String db_url = "jdbc:mysql://testing/OPEN_SOURCE";
String db_user = "root";
String db_pass = "password";
Class.forName("org.gjt.mm.mysql.Driver");
Connection myConn = DriverManager.getConnection(db_url, db_user, db_pass);
Statement stmt = myConn.createStatement();
ResultSet rs_lastBeat = stmt.executeQuery("SELECT NO, SERVICENAME,SERVERNAME,PROGNAME,UDATE, UTIME,LASTTRANS FROM LAST_BEAT");
if (rs_lastBeat != null) {
while (rs_lastBeat.next()) {
String no = rs_lastBeat.getString("NO");
String servicesname = rs_lastBeat.getString("SERVICENAME");
String servername = rs_lastBeat.getString("SERVERNAME");
String programname = rs_lastBeat.getString("PROGNAME");
String udate = rs_lastBeat.getString("UDATE");
String utime = rs_lastBeat.getString("UTIME");
String lasttran = rs_lastBeat.getString("LASTTRANS");
String colorStr = "";
if(utime=="10"){
colorStr = "green";
}else if(utime=="7"){
colorStr ="red";
}
%>
<%
try {
String dateInput, timeInput;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");

// Parameter 1 is the date (yyyy/mm/dd), and Parameter 2 is the time (hh:mm:ss).

dateInput = rs_lastBeat.getString("UDATE");
timeInput = rs_lastBeat.getString("UTIME");

// Parse the Date.
Date d = formatter.parse(dateInput + " " + timeInput);

// Create 2 Calendar objects. The current time is automatically read into a Calendar object.

GregorianCalendar calInput = new GregorianCalendar();
GregorianCalendar calSystem = new GregorianCalendar();

// Here we need to override the default time of the Calendar, which is read from the
// current system time when you create the GregorianCalendar object.

calInput.setTime(d);

// Adding -1 to the DATE field of the system time, resulting a date of 24 hours ago...

calSystem.add(Calendar.DATE, -1);

// OK, finally this is it... calInput.before() will do the compare...
// Because calSystem is actually 24 hours before the current time...
// so calInput.before(calSystem) will just check if the time you input is 24 hours earlier.

if (calInput.before(calSystem)) {
System.out.println("The time you input is 24 hours earlier than the current time!");
} else {
System.out.println("OK, you entered a valid time.");
}
} catch (ParseException ex) {
System.err.println("You must enter the right format of the date and time.");
}

%>

<html>
<head>
<title>NEW</title>
< ;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#000000" text="#FFFFFF">
<p align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Welcome!
<%= request.getParameter("userName")%></b></font></p>
<ul&g t;
</ul>
<div align="left">
<p>Checking</p>
<ul>
</ul>

</div>
<div align="left">
<table width="50%" border="1">
<tr>
<td>No</td>
<td>Services Name</td>
<td>Server Name</td>
<td>Program Name</td>
<td>Current Time (CT)</td>
<td>Update Time (UT)</td>
<td>CT-UT=lapse</td>
</tr>
<tr>
<td& gt;<%= no%></td>
<td><%= servicesname%></td>
<td><%= servername %></td>
<td><%= programname %></td>
<td>test</td>
<td><%= utime %></td>

<td><%= calSystem %></td>

</tr>
</table>
</div>
</body>
</html>
<%

}
}
stmt.close();
myConn.close();
%>

----------------------------------------------------------------------- -

PLEASE HELP ME !!!!!
And also, I the out.println not able to view on the jsp when I load. :(
regards, jasmine


Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: URGENT!!! one day left. Posted: Sep 23, 2002 9:33 AM
Reply to this message Reply
jasmine,

A couple of recommendations.

1. I would use a java bean for all of this, move the code out of jsp.
2. You prpbably are getting some exceptions somewhere, if you wrap everything in a try/catch/finally block this would help you track it down.

3. in the page directive you should specify a errorpage then in the error page you can catch the exception. You have a catch for the parse but what about the others ?

If you want to talk more about this you can email me at dhill@novell.com or yahoo messenger "ssswdon"


HTH

Don

Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: URGENT!!! one day left. Posted: Sep 23, 2002 11:41 AM
Reply to this message Reply
I don't have the db but try this.

-------------------------------------------------
<%@ page language="java"
import="java.sql.*,java.util.Date,java.util.*,java.text.*"
%>

<html>
<head>
<title>NEW</title>
< ;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#000000" text="#FFFFFF">
<p align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1">
<b>Welcome! <%= request.getParameter("userName")%>
</b>
</font>
</p>
<ul>
</ul>
<div align="left">
<p>Checking</p>
</ul>
</div>
<div align="left">
<table width="50%" border="1">
<tr>
<td>No</td>
<td>Services Name</td>
<td>Server Name</td>
<td>Program Name</td>
<td>Current Time (CT)</td>
<td>Update Time (UT)</td>
<td>CT-UT=lapse</td>
</tr>

<%
String db_url = "jdbc:mysql://testing/OPEN_SOURCE";
String db_user = "root";
String db_pass = "password";
Class.forName("org.gjt.mm.mysql.Driver");
Connection myConn = DriverManager.getConnection(db_url, db_user, db_pass);
Statement stmt = myConn.createStatement();
ResultSet rs_lastBeat = stmt.executeQuery("SELECT NO, SERVICENAME,SERVERNAME,PROGNAME,UDATE, UTIME,LASTTRANS FROM LAST_BEAT");
GregorianCalendar calInput = new GregorianCalendar();
GregorianCalendar calSystem = new GregorianCalendar();
if (rs_lastBeat != null) {
while (rs_lastBeat.next()) {
String no = rs_lastBeat.getString("NO");
String servicesname = rs_lastBeat.getString("SERVICENAME");
String servername = rs_lastBeat.getString("SERVERNAME");
String programname = rs_lastBeat.getString("PROGNAME");
String udate = rs_lastBeat.getString("UDATE");
String utime = rs_lastBeat.getString("UTIME");
String lasttran = rs_lastBeat.getString("LASTTRANS");
String colorStr = "";
if(utime=="10"){
colorStr = "green";
}
else if(utime=="7"){
colorStr ="red";
}
%>
<%
try {
String dateInput, timeInput;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");

// Parameter 1 is the date (yyyy/mm/dd), and Parameter 2 is the time (hh:mm:ss).

dateInput = rs_lastBeat.getString("UDATE");
timeInput = rs_lastBeat.getString("UTIME");

// Parse the Date.
Date d = formatter.parse(dateInput + " " + timeInput);

// Create 2 Calendar objects. The current time is automatically read into a Calendar object.

calInput = new GregorianCalendar();
calSystem = new GregorianCalendar();

// Here we need to override the default time of the Calendar, which is read from the
// current system time when you create the GregorianCalendar object.

calInput.setTime(d);

// Adding -1 to the DATE field of the system time, resulting a date of 24 hours ago...

calSystem.add(Calendar.DATE, -1);

// OK, finally this is it... calInput.before() will do the compare...
// Because calSystem is actually 24 hours before the current time...
// so calInput.before(calSystem) will just check if the time you input is 24 hours earlier.

if (calInput.before(calSystem)) {
System.out.println("The time you input is 24 hours earlier than the current time!");
}
else {
System.out.println("OK, you entered a valid time.");
}

}
catch (ParseException ex) {
ex.printStackTrace();
System.err.println("You must enter the right format of the date and time.");
}
%>
<tr>
<td><%= no%></td>
<td><%= servicesname%></td>
<td><%= servername %></td>
<td><%= programname %></td>
<td>test</td>
<td><%= utime %></td>

<td><%= calSystem %></td>
</tr>
<%
}
}
%>
</table>
</div>
</body>
</html>
-------------------------------------- -----------------

Flat View: This topic has 2 replies on 1 page
Topic: Compatibly problem Mac and Window Previous Topic   Next Topic Topic: JOptionPane Problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use