p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Java > Java and JDK > JSP Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 22nd, 2004, 04:17 PM
Authorized User
Points: 64, Level: 1
Points: 64, Level: 1 Points: 64, Level: 1 Points: 64, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sequencial ID by date Java

I want to generate ID number which will be reset everyday.
9/22/04 (1, 2, 3, 4, 5, .....)
9/23/04 (1, 2, 3, 4, 5, .....)
 I am using JSp and recording the dates and creating autonumber Id, but i also want another ID by date.
Any help!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old September 22nd, 2004, 05:10 PM
Friend of Wrox
Points: 422, Level: 7
Points: 422, Level: 7 Points: 422, Level: 7 Points: 422, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello,

Not sure what you mean.
What are the numbers for?
It is possible to return days as the day of the year i.e. 1 - 365, there are solutions in the sun java forums that go into how to use calendar in detail, but here's a snippet of mine that shows how to do it.

import java.util.*;

public class getToday
{
 public String getToday(int offset)
    {
        Calendar cal = Calendar.getInstance();

        int dayOfYear = cal.get(Calendar.DAY_OF_YEAR); // get today
        offset = dayOfYear + offset; // add any offset to today
        cal.set( Calendar.DAY_OF_YEAR, offset); // set day required using offset

        String today = (cal.get(Calendar.YEAR)) + "/" + // format date for entry to database
        (cal.get(Calendar.MONTH)+1) + "/:" +
        (cal.get(Calendar.DAY_OF_MONTH)) + " Here is day of year: " +
        (cal.get(Calendar.DAY_OF_YEAR));

        return today;
    }
}

If you simply want to know whether the date has changed since it was last opened you will need a place to store the 'last opened' date. I dont know where you could put this other than in a database table.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old September 23rd, 2004, 11:31 AM
Authorized User
Points: 64, Level: 1
Points: 64, Level: 1 Points: 64, Level: 1 Points: 64, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear angrycat, Thanks.
But this is not what i want. I want to assign a job number for a user request form. Our dept. wants the job number to be reset everyday. Like say for example, if there are some job requests today it will get the number assigned sequentially 1, 2, 3, 4 …and it will follow as many requests are there for today. But tomorrow the job requests have to start with number 1, 2, 3, 4 …. So, everyday the job number will reset to one. I am having problem.
I am trying to compare the today’s date with the date of the last record entered in the database, but getting errors.
Thanks again.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old September 23rd, 2004, 01:16 PM
Authorized User
Points: 64, Level: 1
Points: 64, Level: 1 Points: 64, Level: 1 Points: 64, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sharing the code.
<%@ page contentType="text/html; charset=utf-8" import="java.sql.*, javax.mail.*, javax.mail.internet.*, java.util.*" errorPage="error.jsp"%>


<%
// define variables and assign values to variables
String Client_Time = request.getParameter("Client_Time"); //Value: new java.util.Date() Getting the system date and time from the client
String request_Date = request.getParameter("request_Date"); //User typed date in a textbox
 int Day_id = 0; //initialized the day it

//load the MS Access JDBC driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    //open a connection to the "Programming_Job_Request" database
    String url="jdbc:odbc:Programming_Job_Request";

    Connection testConn= DriverManager.getConnection(url,"test1","test1");

%>


<%
  String jsql2="Select * from Job_History ORDER by ID DESC";
  Statement stmt2 = testConn.createStatement(ResultSet.TYPE_SCROLL_SEN SITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs1 = stmt2.executeQuery(jsql2);


//The problem is here.
//check the date and increment the day id if already a id exist by that date
while(rs1.first()){
String pre_request_Date= rs1.getString("request_Date");
if (request_Date != pre_request_Date){
 Day_id = 1;
 }
 else{
 Day_id = Day_id +1;

//Print to Browser
 //out.println(jsql2);
 //Print to System
System.out.println(jsql2);
}
//System.out.println(Day_id);

}
rs1.close();

%>



<%
  //place query results in a ResultSet object and insert to teh DB

   String jsql="INSERT INTO Job_History(Day_id, request_Date, Client_Time) VALUES (?, ?, ?)" ;
    //Print to Browser
    //out.println(jsql);
    //Print to System
    //System.out.println(jsql);

    %>>>><%=Client_Time%>>>>><%

 //create a statement object for sending SQL queries
    PreparedStatement stmt = testConn.prepareStatement(jsql);
    stmt.setInt(1, Day_id);
   stmt.setString(2, request_Date);
    stmt.setString(3, Client_Time);

    // stmt.setInt(7, Integer.parseInt(uid));
   stmt.executeUpdate();

   //clean up current resultse object
     if (stmt!=null)stmt.close();
 %>


    <%
  String jsql1="Select * from Job_History where Client_Time = '"+Client_Time+"'";
  //"SELECT * FROM user WHERE user_name = '"+Client_Time+"'";
  Statement stmt1 = testConn.createStatement();
ResultSet rs = stmt1.executeQuery(jsql1);
while(rs.next()){
String user_id= rs.getString("ID"); //An AutoNumbered ID from the Database and the Client time will print the current ID

%>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Information Technology Resources</title>
</head>
<body>
<table border="0" width="450" id="table10">
<form method="POST" action="Implementation_estimated.jsp">

    <tr>
        <td><h3>Information Technology Resources<br>Programming Request Form</h3><br>

<table border="0" width="480" id="table11" height="0">
    <tr>
        <td colspan="4" width="0">
                <b>Control Number:<%=user_id%></b>&nbsp;(Please remember this Number)</td>

    </tr>
    <tr>
        <td colspan="4">
                Day ID: <%=Day_id%></td>
    </tr>
<tr>
        <td colspan="4">
                Request Date:<%=request_Date%>&nbsp;
                </td>
    </tr>
<%
}
rs.close();
%>
<%
 if (testConn!=null)testConn.close();
%>
</table>
</body>
</html>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old September 23rd, 2004, 03:05 PM
Friend of Wrox
Points: 422, Level: 7
Points: 422, Level: 7 Points: 422, Level: 7 Points: 422, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

You cannot compare strings with '=' so:

if (request_Date != pre_request_Date)

is incorrect.

You should use .equals.

if (string1.equals(string2))

or with a literal

if (string1.equals("myHardCoding"))




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old September 23rd, 2004, 04:19 PM
Authorized User
Points: 64, Level: 1
Points: 64, Level: 1 Points: 64, Level: 1 Points: 64, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mr. angrycat,
I resolved it,
but now its always 1. cant tell if it is comparing
<%
/* */
  String jsql2="Select * from Job_History1 ORDER by ID DESC";
  Statement stmt2 = testConn.createStatement(ResultSet.TYPE_SCROLL_SEN SITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs1 = stmt2.executeQuery(jsql2);


//The problem is here.
//check the date and increment the day id if already a id exist by that date
rs1.first();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
//this is also ok to get the util date in string format
//GregorianCalendar cal = new GregorianCalendar();
//String s = formatter.format(cal.getTime());

java.util.Date now = new java.util.Date();
String s = formatter.format(now); //convert date to string


//String pre_request_Date= rs1.getString("request_Date");

String pre_request_Date = formatter.format(rs1.getDate("request_Date"));

if (s.equals(pre_request_Date)){
 Day_id = Day_id +1;
 }
 else{
 Day_id = 1;

//Print to Browser
 //out.println(jsql2);
 //Print to System
//System.out.println(jsql2);
}
System.out.println("Current ID: " + Day_id);
System.out.println("Today: " + s);
System.out.println("Previous Date Record: " + pre_request_Date);

rs1.close();

%>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old September 23rd, 2004, 04:38 PM
Authorized User
Points: 64, Level: 1
Points: 64, Level: 1 Points: 64, Level: 1 Points: 64, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i think i resolved it. Thanks to all.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old September 24th, 2004, 02:19 PM
Friend of Wrox
Points: 422, Level: 7
Points: 422, Level: 7 Points: 422, Level: 7 Points: 422, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use the ! not equals operater with this, I THINK it goes before the brackets:

if !(s.equals(pre_request_Date))

Cant be sure if this is the right place but it can definately be done

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access Eval("ID") in Java Script Harjinder ASP.NET 2.0 Professional 0 May 19th, 2008 02:16 AM
Date in java hafizmuhammadmushtaq Java Basics 3 April 17th, 2008 11:37 PM
problem with java.util.Date kanoorani Java Basics 1 April 20th, 2007 02:48 AM
'this.ID = id;' in class construction holf BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 October 6th, 2006 11:58 AM
why not index.asp?id=1 can be www.myweb.com/?id=1 BurhanKhan Classic ASP Professional 11 September 6th, 2004 03:06 PM



All times are GMT -4. The time now is 07:36 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc