GeeCON Prague 2014*
The moose likes Servlets and the fly likes using init-param to set a value in a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "using init-param to set a value in a table" Watch "using init-param to set a value in a table" New topic
Author

using init-param to set a value in a table

vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
I have a table for online job applications. This table has a 'End_date_time' column which is a VARCHAR, its the date time ceiling for a job offer.

I have a JobBean and a JobDAO. In the JobDAO i have a method selectJobBean(long jobId), jobId being the primary key for this table. I also have a static method initializeBean(JobBean jBean) where I initialize the status of a job bean and set the status to 'OPEN' or 'CLOSED' based on the current date-time being greater than or less than the 'End_date_time' value respectively.

And I call this initializeBean() from the parameterized constructor of JobBean class, JobBean(long jobId).

This works fine. But I am not too happy with this approach. I could use a database trigger to set the status of a job.

But is there a way to do this using an init-param making minimal changes? I am controlling the whole process using a JobControllerServlet.


[ October 12, 2006: Message edited by: vishwanath nadimpally ]
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

Few comments (haven't read through the code completely)...

Why are you saving the date data using Strings? JDBC can handle dates using setDate().

Don't use triggers, especially not for what you're describing (business logic). You could say you don't need the status field (since its values is predetermined by 2 other fields), but its likely you will have other values such as "open" "close" "on-hold" "paused" etc, so having the field is useful.


My Blog: Down Home Country Coding with Scott Selikoff
vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
Originally posted by Scott Selikoff:
Few comments (haven't read through the code completely)...

Why are you saving the date data using Strings? JDBC can handle dates using setDate().

Don't use triggers, especially not for what you're describing (business logic). You could say you don't need the status field (since its values is predetermined by 2 other fields), but its likely you will have other values such as "open" "close" "on-hold" "paused" etc, so having the field is useful.


The javascript calendar I am using to get the date returns a date time in this format "MM/dd/yyyy hh:mm:ss aaa" andI found I never knew about the setDate(), Thanks for that.

Also, the same job can be "opened" at a later date just by changing the date from an 'admin screen', So the status column is required.
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

Maybe I'm missing something (probably) but how edoes this relate to init-params, or better question, how is this a servlet issue?

BTW- I don't see the problem with explicitly setting the status every time. You could just write a static helper method that determines the status based on the input. It would still be better to put this in java code rather than a db trigger.
vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
I dont think you missed anything. I got confused somehow that I can use the 'End_date_time' as an init-param and set the status in my servlet (Using a static helper ofcourse.) but then I would need a jobId (primary key) of the row I want to update.

So I am going to stick with what I have. Thanks for suggestions.
 
GeeCON Prague 2014
 
subject: using init-param to set a value in a table