basirana
asked on
HashMap in JSP forms
Hi
Below is running JSP program which I have written to update values from webreport
I have problem
Senario : I am trying to display each records in table row and data in one textbox.
problem is when I try to update the record only one record can get updated at one time
because each row consist of one update button...
I want to remove multiple update button and put only one update button and pass all records to update.
I am not sure how to do this process. Can you please help by change below code.
<%@ page language="java" import="java.sql.*" %>
<%!
Connection connection ;
Statement statement ;
ResultSet rs ;
ResultSetMetaData rsmd ;
%>
<HTML>
<HEAD>
<TITLE>
Functional Data
</TITLE>
</HEAD>
<BODY>
<%
Class.forName("oracle.jdbc .driver.Or acleDriver ") ;
connection = DriverManager.getConnectio n( "jdbc:oracle:thin:@oracle" , "scott", "tiger") ;
statement = connection.createStatement () ;
rs = statement.executeQuery( "SELECT * FROM emp") ;
rsmd = rs.getMetaData() ;
%>
<h3> Functional Report</h3>
<TABLE WIDTH="100%" BORDER="+5" >
<TR > <h5>
<%
for(int i = 1 ; i <= rsmd.getColumnCount() ; i++) {
%> </h5>
<TH>
<font size=2><%= rsmd.getColumnLabel(i) %></font>
</TH>
<% } %>
</TR>
<% while(rs.next()) { %>
<form method="POST" action ="update.jsp">
<TR>
<TD height = 10><font size=2> <input type="text" name="p1" value= <%= rs.getString(1) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p2" value= <%= rs.getString(2) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p3" value= <%= rs.getString(3) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p4" value= <%= rs.getString(4) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p5" value= <%= rs.getString(5) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p6" value= <%= rs.getString(6) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p7" value= <%= rs.getString(7) %> ></font> </TD>
<TD height = 10><input type="submit" value="update">
</td>
</TR>
</form>
<% } %>
</TABLE>
</BODY>
</HTML>
Thank
Below is running JSP program which I have written to update values from webreport
I have problem
Senario : I am trying to display each records in table row and data in one textbox.
problem is when I try to update the record only one record can get updated at one time
because each row consist of one update button...
I want to remove multiple update button and put only one update button and pass all records to update.
I am not sure how to do this process. Can you please help by change below code.
<%@ page language="java" import="java.sql.*" %>
<%!
Connection connection ;
Statement statement ;
ResultSet rs ;
ResultSetMetaData rsmd ;
%>
<HTML>
<HEAD>
<TITLE>
Functional Data
</TITLE>
</HEAD>
<BODY>
<%
Class.forName("oracle.jdbc
connection = DriverManager.getConnectio
statement = connection.createStatement
rs = statement.executeQuery( "SELECT * FROM emp") ;
rsmd = rs.getMetaData() ;
%>
<h3> Functional Report</h3>
<TABLE WIDTH="100%" BORDER="+5" >
<TR > <h5>
<%
for(int i = 1 ; i <= rsmd.getColumnCount() ; i++) {
%> </h5>
<TH>
<font size=2><%= rsmd.getColumnLabel(i) %></font>
</TH>
<% } %>
</TR>
<% while(rs.next()) { %>
<form method="POST" action ="update.jsp">
<TR>
<TD height = 10><font size=2> <input type="text" name="p1" value= <%= rs.getString(1) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p2" value= <%= rs.getString(2) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p3" value= <%= rs.getString(3) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p4" value= <%= rs.getString(4) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p5" value= <%= rs.getString(5) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p6" value= <%= rs.getString(6) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p7" value= <%= rs.getString(7) %> ></font> </TD>
<TD height = 10><input type="submit" value="update">
</td>
</TR>
</form>
<% } %>
</TABLE>
</BODY>
</HTML>
Thank
ASKER
Thanks for ur reply it sounds similar to my thought but what about the name of the parameter it will be repeated.
I was thinking something like below. I am not sure how to access paramters to update in the database.
I have one more problem. below senario let say there are 100 textboxs are diplayed and only 10 values are entered but I am trying to access 100 there are 90 parameter that are not needed but updated in database. which is time consuming and make system slow.
How to solve the problem. please help me.
<form method="POST" action ="update.jsp">
<% while(rs.next()) { %>
<TR>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(1) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(2) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(3) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(4) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(5) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(6) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(7) %> ></font> </TD>
</TR>
<% } %>
<input type="submit" value="update">
</form>
I was thinking something like below. I am not sure how to access paramters to update in the database.
I have one more problem. below senario let say there are 100 textboxs are diplayed and only 10 values are entered but I am trying to access 100 there are 90 parameter that are not needed but updated in database. which is time consuming and make system slow.
How to solve the problem. please help me.
<form method="POST" action ="update.jsp">
<% while(rs.next()) { %>
<TR>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(1) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(2) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(3) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(4) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(5) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(6) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p"+<%i++%> value= <%= rs.getString(7) %> ></font> </TD>
</TR>
<% } %>
<input type="submit" value="update">
</form>
just keep the same name for all text box
in jsp use getParametervalues("textbo xName");
getParameterValues()
public java.lang.String[] getParameterValues(java.la ng.String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
If the parameter has a single value, the array has a length of 1.
Parameters:
name - a String containing the name of the parameter whose value is requested
Returns:
an array of String objects containing the parameter's values
then iterate and update in DB
Krish
in jsp use getParametervalues("textbo
getParameterValues()
public java.lang.String[] getParameterValues(java.la
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
If the parameter has a single value, the array has a length of 1.
Parameters:
name - a String containing the name of the parameter whose value is requested
Returns:
an array of String objects containing the parameter's values
then iterate and update in DB
Krish
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<% while(rs.next()) { %>
<form method="POST" action ="update.jsp">
<TR>
<TD height = 10><font size=2> <input type="text" name="p1" value= <%= rs.getString(1) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p2" value= <%= rs.getString(2) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p3" value= <%= rs.getString(3) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p4" value= <%= rs.getString(4) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p5" value= <%= rs.getString(5) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p6" value= <%= rs.getString(6) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p7" value= <%= rs.getString(7) %> ></font> </TD>
<TD height = 10><input type="submit" value="update">
</td>
</TR>
</form>
<% } %>
to be like
<form method="POST" action ="update.jsp">
<% while(rs.next()) { %>
<TR>
<TD height = 10><font size=2> <input type="text" name="p1" value= <%= rs.getString(1) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p2" value= <%= rs.getString(2) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p3" value= <%= rs.getString(3) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p4" value= <%= rs.getString(4) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p5" value= <%= rs.getString(5) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p6" value= <%= rs.getString(6) %> ></font> </TD>
<TD height = 10><font size=2> <input type="text" name="p7" value= <%= rs.getString(7) %> ></font> </TD>
</td>
</TR>
<% } %>
<input type="submit" value="update">
</form>
Then you need to update your update.jsp accordingly.