File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes JDBC-3 Design Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "JDBC-3 Design Question" Watch "JDBC-3 Design Question" New topic
Author

JDBC-3 Design Question

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
In JDBC-3 each video gets an edit button which should allow the user to edit that video.
Is there a way using html to uniquely identify each edit button by the table row it is in so that video is selected for editing when the button is clicked, or would it be okay to have the button bring up a form on which the user could input the information about which video they want to edit?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
You will need an input tag of type hidden. Use the video title as your primary key (to distinguish which video you want). You don't need an extra form.
[ September 21, 2002: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Louise Haydu
Ranch Hand

Joined: Aug 17, 2000
Posts: 51
I understand the concept of the hidden field, but am having difficulty determining how the hidden field can be associated with the button that is pressed.
Am I correct in assuming that we won't need JavaScript for this assignment?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
I don't know JavaScript, so please don't include it.
Louise Haydu
Ranch Hand

Joined: Aug 17, 2000
Posts: 51
OK... so JavaScript is out.
Assuming that the HTML page is using one form that contains a table of vidoes, each with it's own edit button, I am still having trouble seeing how the edit button can be associated with a hidden field when the user presses the "Edit" button for a video.
Any hints would be appreciated.
.. By the way, I was able to do this without a hidden field, but received a nit pick for my approach.
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 129
Each edit button controls a form... each form knows the title of the video it's currently listing... the database can find each video by title......


Darryl Failla
Sun Certified Java 2 Programmer
Louise Haydu
Ranch Hand

Joined: Aug 17, 2000
Posts: 51
In a previous post called "JDBC problem with buttons" (submitted by Peter Gragert on 8/15/02 ... sorry, but I don't know how to put in a link to a previous posting), one of the replies in this thread (I think from Marilyn) indicated that you can do this assignment with only *one* form, which is what I'm trying to do.
I was hoping to avoid having a form for each video title.
[ September 23, 2002: Message edited by: Louise Haydu ]
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
I'm thinking of re-using the existing form under another title to differentiate between a new video and an altered one. As far as hidden fields go, isn't this essentially the same mechanism we use to pass the token around? The value in this case will have to be unique for each video, but setting up the form should be almost the same, should it not?
Louise Haydu
Ranch Hand

Joined: Aug 17, 2000
Posts: 51
Yes, hidden fields are the same mechanism we use to pass the token around.
But I'm not sure we are talking about the same form. I'm talking about using hidden fields in the form produced by the "ListVideoServlet" in which I have a table containing a row for each video. This table exists within a single form. The alternative is to set up the HTML so that a form appears in each row of the form.
I think you are talking about the form that will come up when a video is selected for editing. In that case, it will be very similar to the form used to add a new video.
[ September 23, 2002: Message edited by: Louise Haydu ]
[ September 23, 2002: Message edited by: Louise Haydu ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
Originally posted by Louise Haydu:
In a previous post called "JDBC problem with buttons" (submitted by Peter Gragert on 8/15/02 ...


You can click on the "edit" icon (the paper and pencil one) of this post to see how I created the link.
[ September 23, 2002: Message edited by: Marilyn de Queiroz ]
Louise Haydu
Ranch Hand

Joined: Aug 17, 2000
Posts: 51
I tried to look at your link via "edit", but received a message telling me that I couldn't do it because I'm not a moderator or administrator.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
Oh. Sorry. UBB used to let people look but not change via edit. Try using the "quote" but instead of clicking the "Add Reply" button, use the back button on your browser to cancel the reply.

More info here.
[ September 23, 2002: Message edited by: Marilyn de Queiroz ]
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Hi Louise, I wasn't here lately. You already did what I suggested in my last mail to you. So here my 'findings':
If I have ONE form with ONE TABLE of editbuttons I see too no possibiltiy to fill a 'hidden' "thing" with info of which edit button is pressed meaning which video should be edited.
Up to I use ONE form with a table and the NAME of the editbutton is related to the video in the same 'record' ... .
A possibility would be to have ONE table of FORMS (for each video one) then the relation is one to one and could deliver a second solution.
If this is correct, dear nitpickers, to what solution should 'our' solution converge?
Or is there a (totally) different solution (not using javascrip)???
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
What?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
I use ONE form with a table and the NAME of the editbutton is related to the video in the same 'record' ...

Yep. That's the one.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Originally posted by Peter Gragert:
[QB]Hi Louise, I wasn't here lately. You already did what I suggested in my last mail to you.

You guys got a little thing going on behind our backs, eh? If you share your secrets with us (cryptically, of course) we promise not to tell anyone...
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
You are right Pauline !
Struggeling with an assignment and seeing no solution but one which is nitpicked ... But as you see, we are smart enough to tell our story here too.
Because I am very busy with my VERY last 6 weeks of giving lectures (early retirement) I realized this thread so late ... .
By the way I had another 'private' info with Marilyn about another very meaningful assignment (at least in my opinion), which I did not put here because of 'copyright' problems ... but this does not belong here. Sorry.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
oh, now I get it! One way is a table with many forms inside, the other is a form with a table inside!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
It's too bad that this is almost at the end of the current course. The people who have passed this point don't hang out here much any more.
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20729
    ∞

It seems to me that the many form technique is about the only way to go. If you go with one big form with many submit buttons, then how do you control the hidden fields that reflect which title goes with which submit?
If there is a way to do a big form, I would be interested in seeing it.


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Ha, this is exactly what was asked earlier and see my cry for help!
I had a much nicer first version:
Indicate the video by a radiobutton and then use below in the form a delete and an edit button.
Peace of cake to realize and it worked already half a year ago ... and now I am in problems with one form one table and two buttons per video ...
Yes it is possible, you prefix a prefix to the name of either the edit or delete button (name!)to distinguish between them ... in ONE form with ONE and to indicate which video is meant.
TABLE, just got it working
[ October 02, 2002: Message edited by: Peter Gragert ]
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 129
I'm with the disgrutled masses on this one. Maybe everyone is just caught up in confusing terminology here. When I see "Edit" and "Delete" buttons being called for in the assignment, I see Submit buttons in each record. (That seems to me to be the norm in the real world).
Assuming the above is true, I can't see any other reason for a Submit button other than to control a form. I'm not sure if this constitutes a table of forms, a form of tables, a form of forms, or whatever. But that's how I made it work. If this is the wrong approach, then maybe the assignment description needs a clearer objective.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
confusing terminology

I'm sorry if I helped to confuse things. The table is not inside a <form> tag.

Each row (video object) has its own edit (submit) button. Each edit button has it's own <form> tag. (So will each delete button.) You pass a hidden parameter which distinguishes which video you want to work with. The hidden parameter is the title of the video you want to edit.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
Originally posted by Carol Murphy:
In JDBC-3 each video gets an edit button which should allow the user to edit that video.
Is there a way using html to uniquely identify each edit button by the table row it is in so that video is selected for editing when the button is clicked, or would it be okay to have the button bring up a form on which the user could input the information about which video they want to edit?

Getting back to this original question, the edit button should bring up a "form" that looks just like the addvideo.html "form" that we have been using to add videos since Servlets-4. The only difference is that this time the addvideo "form" should have the title, star, etc., information already visible and ready to be edited. You use a <form> tag to accomplish this.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
Okay, this is good news because this is how I decided to approach the problem. Now my difficulty is getting the right data input into the appropriate fields. The only one that works for me is the first one. After that all I get is a JDBC syntax error. But at least I'm going in the right direction!
Manju Jain
Ranch Hand

Joined: Feb 08, 2001
Posts: 168
Now, I dont have to rack my brains anymore on how to fit the entire stuff in one form.
But, I do have a side problem. Able to pass the video title to a hidden variable but in the AddVideoSevlet, only part of the string is held in the hidden field. That is, if the title is 'The God is crazy' , the hidden field contains only 'The' ,truncating the rest. But, if I look at the source html code of ListVideoServlet, full string is being passed to the hidden field. Trying to figure this out.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
Remember Reverse2Servlet? If you're not careful you will only get part of the string to reverse.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
I had that same problem too, until I looked back at the servlet assignments. The answer is there. My problem is the fields that come after the first one. I can't get the values to print out there. I think it has something to do with using ResultSet improperly, because I'm not accessing just one video, I'm accessing the whole data base. Imagine my surprise when I tried to edit one video, and ended up editing them all. now I have a data base full of about twenty identical entries! ACkkkkkkk!
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 129
Check the WHERE clause in your UPDATE statement. You may find that there isn't one.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
You're right, there isn't one. Because I thought that I was dealing with one record only. Boy, was I wrong! I have to have a look at the ResultSet documentation and figure out what's going on. Once I do that, I hope it all comes together!
Manju Jain
Ranch Hand

Joined: Feb 08, 2001
Posts: 168
Yep, ReverseServlet was such a direct hint that I couldn't miss it.
One sql doubt:
In oracle you can have a sql statement like select * from videos where rownum=2 ;
but in mysql is there an equivalent varaiable for row number I looked in the mysql manual but couldn't find one.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1757
    
    3
Rownum in SQL is anathema. It's evil. Forget you ever heard about it. Trust me on this one.
(Ok, don't forget you heard about it. Use SQL for a year or so. Then revisit rownum, by which time you should be able to come up with a whole laundry list of reasons to avoid rownum.)
Ok, I'll tone things down. There are a couple of handy uses of rownum, but it should pretty much never be used as a first choice solution.
Handy use of rownum. Say you want to see a couple rows of data in a table and you don't particular care *which* rows -- just some rows of data. In which case,
select * from my_table where rownum < 20
will do the trick.
Otherwise, there's always a better way. I posted an evil trick with rownum elsewhere on JavaRanch once, but I can't seem to find it. If I do, I'll post a link.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1757
    
    3
Actually, I don't think rownum is part of SQL at all. In Oracle it's considered a "pseudocolumn."
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1757
    
    3
Found it. What you should get from that post is that rownum doesn't do what you may think it does; you can't use it with certain operators such as = , > , between...and , etc.; and there are some very unexpected interactions betweeen rownum and order by.
Rownum, bah!
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1757
    
    3
Originally posted by Manju Jain:

One sql doubt:
In oracle you can have a sql statement like select * from videos where rownum=2 ;

Have you actually ever run such a query? Do you understand the results? (That is, why that query returns zero rows.)
For an explanation, see following the link in my above post to the evil rownum trick post.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1757
    
    3
Why are folks looking around for all these exotic solutions anyhow? Darryl practically gives the answer away in his post!
Manju Jain
Ranch Hand

Joined: Feb 08, 2001
Posts: 168
Michael, I just couldn't get it out of my head that 'one form' solution is probably impossible or atleast frustrating. I just wanted to try this. The value of edit button for each video as EditRec + ResultSet.getRow(). I then extract only the row number from this param in AddVideoServlet. Hope to use this in
select * from videos where rownum = getRow(). This makes sure that correct row gets updated. The reason I want to access the row number is quite flimsy actually. In India we have any no of films with the same title. Since the field 'TITLE' is not specified unique in the table , I thought the duplicate values in this column will affect the query results. So, rownum will come in handy.
Getting back to 'one form' prob, no hidden field will be required as each edit button's value will be different which will be accessed in the AddVideo.
Michael , your link clearly discourages using rownum and you're right. I've come across a keyword 'limit' and I feel is a good substitute for rownum. Like,
"select * from videos limit " + getRow()-1 ,1 ;
-1 because row no. starts from zero.
This query returns only one row.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1757
    
    3
Manju Jain in bold:
Michael, I just couldn't get it out of my head that 'one form' solution is probably impossible or atleast frustrating.
I'm staying out of that debate for now.

I just wanted to try this. The value of edit button for each video as EditRec + ResultSet.getRow(). I then extract only the row number from this param in AddVideoServlet. Hope to use this in
select * from videos where rownum = getRow(). This makes sure that correct row gets updated.

Addendum to "never use rownum": especially never reuse the value of rownum for anything. Anything. Ever. It's a fabrication of the query running at the split second the query runs. Nothing guarantees that that row will return that same value ever again.
Given all these rownum conniptions, how are you planning to update the actual row? Can't use rownum = something.
The reason I want to access the row number is quite flimsy actually.
In India we have any no of films with the same title.

Only in India? Same thing happens with the rest of the world.
Since the field 'TITLE' is not specified unique in the table , I thought the duplicate values in this column will affect the query results.
I believe Marilyn addressed this point some time ago. For the purpose of this assignment, I believe we are to assume all titles are unique.
Can we get an official word from MdQ on this?
(If that's true, maybe it should say so in the assignment.)
Sure, that's not how you'd do things in the real world, but the point of this assignment isn't a real-world database modeling exercise. Real-world databases have keys, constraints, etc.
So, rownum will come in handy.
Rownum doesn't guarantee what you're relying on it to guarantee.

I've come across a keyword 'limit' and I feel is a good substitute for rownum. Like,
"select * from videos limit " + getRow()-1 ,1 ;
-1 because row no. starts from zero.
This query returns only one row.

Where'd you find it? Is it an Oracle extension? MySQL? I remain doubtful that the way to go about any of this is to use this limit keyword.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
Since the field 'TITLE' is not specified unique in the table , I thought the duplicate values in this column will affect the query results.[/b]
I believe Marilyn addressed this point some time ago. For the purpose of this assignment, I believe we are to assume all titles are unique.
Can we get an official word from MdQ on this?


Good memory, Michael. For this assignment you should consider the title to be unique and use it as your primary key.

(If that's true, maybe it should say so in the assignment.)

Good point. I'll make that change ASAP (maybe not today, though).


I've come across a keyword 'limit' and I feel is a good substitute for rownum. Like,
"select * from videos limit " + getRow()-1 ,1 ;
-1 because row no. starts from zero.
This query returns only one row.
Where'd you find it? Is it an Oracle extension? MySQL? I remain doubtful that the way to go about any of this is to use this limit keyword.

LIMIT is strictly mySQL. It won't be useful in any other setting. Stick to basic SQL so we don't limit our database options.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC-3 Design Question