Tuan_Jean
asked on
using JSP to update a field for multiple records
I have a table
mytable
----------
userid,
team [The team could only have 3 possible values (ie 1,2,3 with default 1)]
I would want to display [ user id - Team] combination in a table, with the team showing the existing value from database using "SELECT and OPTION" or "INPUT Radio button combination in 3 columns".
I would like to be able to make the changes and have an update button to update all the records with the new value.
How do I do this in JSP?
Thank you.
mytable
----------
userid,
team [The team could only have 3 possible values (ie 1,2,3 with default 1)]
I would want to display [ user id - Team] combination in a table, with the team showing the existing value from database using "SELECT and OPTION" or "INPUT Radio button combination in 3 columns".
I would like to be able to make the changes and have an update button to update all the records with the new value.
How do I do this in JSP?
Thank you.
ASKER
Thank you for the quick response.
I have had db connection setup without problem and know some JSP. The problem I have was trying to use just a button for updating the table. If I have only 1 item, then using "INPUT Radio button combination in 3 columns" with the user_id as the name will work. But I am not sure how to proceed if there are more then 1 items to be updated at anyone time and how to setup the default value for each input using existing data from the database.
Thank you.
I have had db connection setup without problem and know some JSP. The problem I have was trying to use just a button for updating the table. If I have only 1 item, then using "INPUT Radio button combination in 3 columns" with the user_id as the name will work. But I am not sure how to proceed if there are more then 1 items to be updated at anyone time and how to setup the default value for each input using existing data from the database.
Thank you.
Hm, I am still a bit unsecure if I understand your question or not :-/ But anyway here comes an example:
(assuming you have a connection)
<form name="form" action="yourpage.jsp">
<%
try{
String query="Select userid from mytable";
ResultSet rs=statement.executeQuery( query);
while (rs.next()){
String userid=rs.getString("useri d");
out.println("<br>UserID: "+rs.getString("userid"));
String query2="Select team from mytable where userid='"+userid+"'";
ResultSet rs2=statement.executeQuery (query2);
rs2.next();
int team=rs2.getInt("team");
out.println("<SELECT>");
for (int i=1; i<4; i++){
out.println("<OPTION VALUE=\""+i+"\"");
if (team==i){out.println(" SELECTED");}
out.println(">"+i+"</OPTIO N>");
}
out.println("</SELECT>");
}
out.println("<br>");
}
catch(SQLException e){
e.printStackTrace();
}
%>
<input type="submit" name="submit">
</form>
Now you can read (and alter db if neccesary) the choices from the select menus via request.getParameter().
Hope it helps you!
Regards,
Nic
(assuming you have a connection)
<form name="form" action="yourpage.jsp">
<%
try{
String query="Select userid from mytable";
ResultSet rs=statement.executeQuery(
while (rs.next()){
String userid=rs.getString("useri
out.println("<br>UserID: "+rs.getString("userid"));
String query2="Select team from mytable where userid='"+userid+"'";
ResultSet rs2=statement.executeQuery
rs2.next();
int team=rs2.getInt("team");
out.println("<SELECT>");
for (int i=1; i<4; i++){
out.println("<OPTION VALUE=\""+i+"\"");
if (team==i){out.println(" SELECTED");}
out.println(">"+i+"</OPTIO
}
out.println("</SELECT>");
}
out.println("<br>");
}
catch(SQLException e){
e.printStackTrace();
}
%>
<input type="submit" name="submit">
</form>
Now you can read (and alter db if neccesary) the choices from the select menus via request.getParameter().
Hope it helps you!
Regards,
Nic
ASKER
Nic,
You are very close to my question. Perhaps I could put down an example for the page I intended to do:
----------------
name1 1
name2 3
name3 2
[update]
----------------
When I click update, how do I update the name1 record to value 1 and etc. Thank you.
You are very close to my question. Perhaps I could put down an example for the page I intended to do:
----------------
name1 1
name2 3
name3 2
[update]
----------------
When I click update, how do I update the name1 record to value 1 and etc. Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Nic.
No problem. If your problem is solved, you should remember to award the points. ;-)
ASKER
Sorry Nic. I have forgotten to click on Accept button. I have just done it.
It would take a looooooong time to answer this question in detail - could you perhaps write a bit more about how far you are on the subject?
Do you know basic jsp?
Do you know HTML?
Do you have a db-connection?
Do you know java?
Regards,
Nic