Insert specific fields into table dynamically for each row.

Insert specific fields into table dynamically for each row.

There is a table containing 20 fields and 2 of those are empty. The administrator will enter those details in a webpage. So that the field values will insert into the table. For this all the rows displayed and two rows with empty text boxes, he insert there for each row and for each row there is a button "done".if he click on done the values will be inserted into database.Then he enter values for next row. How to do this problem?

but it should not go to another page. he enter one details and just click done on first row and immediately he enters second row details. And now the first row details should appear in the text boxes.

View Answers

May 20, 2011 at 5:05 PM

Modify the code:

1)admin.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function editRecord(){
    var f=document.form;
    f.method="post";
    f.action='done.jsp';
    f.submit();
  }
</script>
</head>
<body>
<br><br>
<form method="post" name="form">
<table border="1">
<tr><th></th><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";

Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr>
<td><input type="hidden" name="id" value="<%=rs.getString(1)%>"></td>
<td><input type="text" name="name" value="<%=rs.getString(2)%>"></td>
<td><input type="text" name="address" value="<%=rs.getString(3)%>"></td>
<td><input type="text" name="contact" value="<%=rs.getString(4)%>"></td>
<td><input type="text" name="email" value="<%=rs.getString(5)%>"></td>
<td><input type="button" name="button" value="Done" style="background-color:green;font-weight:bold;color:white;" onclick="editRecord();" ></td>
</tr>
<%

}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>

2)done.jsp:

<%@page import="java.sql.*"%>
<%
String ide[]=request.getParameterValues("id");
String name[]=request.getParameterValues("name");
String address[]=request.getParameterValues("address");
String contact[]=request.getParameterValues("contact");
String email[]=request.getParameterValues("email");

try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=null;
st=conn.createStatement();
for(int i=0;i<ide.length;i++){
int id=Integer.parseInt(ide[i]);
String n=name[i];
String add=address[i];
int ct=Integer.parseInt(contact[i]);
String e=email[i];
st.executeUpdate("update employee set name='"+n+"',address='"+add+"',contactNo="+ct+",email='"+e+"' where id='"+id+"'");
}
}
catch(Exception e){
System.out.println(e);
}
response.sendRedirect("/examples/jsp/admin.jsp");

%>

May 20, 2011 at 5:55 PM

Thanks for your answer. It is very much useful to me.









Related Tutorials/Questions & Answers:
Insert specific fields into table dynamically for each row.
Insert specific fields into table dynamically for each row.  There is a table containing 20 fields and 2 of those are empty. The administrator... insert there for each row and for each row there is a button "done".if he click
Insert specific fields into table dynamically for each row.
Insert specific fields into table dynamically for each row.  There is a table containing 20 fields and 2 of those are empty. The administrator... insert there for each row and for each row there is a button "done".if he click
Advertisements
Query to insert values in the empty fields in the last row of a table in Mysql database?
Query to insert values in the empty fields in the last row of a table in Mysql database?  I have some fields filled and some fields empty in the last row of my MYSQL database. Now I want to fill up those empty fields in the last
Hoe to refresh a table row dynamically
Hoe to refresh a table row dynamically  Want to refresh a table data... Friend, Is there a link attribute with every row of a table through which we will able to refresh a particular table row?ADS_TO_REPLACE_1 Please clarify
Adding button to each row for the table and adding row to another table
Adding button to each row for the table and adding row to another table  Hi I need to add button to each line in the table(Table data is retrived... row of the table
JavaScript add row dynamically to table
JavaScript add row dynamically to table  ... to add row to a table dynamically then we can also do this with the JavaScript code. In this example we will describe you how to add row dynamically to the table
Delete a Specific Row from a Database Table
Delete a Specific Row from a Database Table   ... the facility for deleting specific row in a database table. Sometimes, you want..., and in this section we are going to do the same that is, how to delete a specific row
getting radio button at start of each row of table - Struts
getting radio button at start of each row of table  i have done the following things, and this is fine for me. But i want radio button at the place... at the start of each row as u saw in above output. So what should i have to do
Server side validation on dynamically generated fields from more than one table on spring framework.
Server side validation on dynamically generated fields from more than one table on spring framework.   Server side validation on dynamically generated fields from more than one table in spring mvc framework
jtable-adding a row dynamically
to add one more row dynamically as a new row 4th if the details are large.but every...jtable-adding a row dynamically  hi..i am doing a project... and if the user want enter the data to a 4th row he must press enter at the end of the 3rd
insert and delete a row programmatically
insert and delete a row programmatically  How to insert and delete a row programmatically ? (new feature in JDBC 2.0
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
delete row from a table in hibernate
delete row from a table in hibernate  is there method to delete row in a table using hibernate like save(-) to insert row
data grid with edit and delete options at each row.
data grid with edit and delete options at each row.  i want to display the table data in the format of data grid with edit and delete options at each row. i need it very urgently. advance thanks
JDBC Delete Row In Table Example
JDBC Delete Row In Table Example : In this tutorial we will learn how delete specific row from the table use mysql JDBC driver.This tutorial defined how one... Deleted specific row in the table successfully... F:\jdbc>java
add image in a row of table
add image in a row of table  i have a table in which i have to add image in its row.i am trying to add the image with the help of label i.e i have... jLabel.setIcon(new ImageIcon("E:/2.jpg"));.But when i pass this jlabel in the row it shows
add image in a row of table
add image in a row of table  i have a table in which i have to add image in its row.i am trying to add the image with the help of label i.e i have... jLabel.setIcon(new ImageIcon("E:/2.jpg"));.But when i pass this jlabel in the row it shows
How to insert data into MySQL Table?
How to insert data into MySQL Table?  Hi, How to insert the data...: With all fields in the query: insert into email(firstname,lastname,email,email...','[email protected]',400); Query OK, 1 row affected (0.01 sec) mysql> insert into email
how to update specific row in on update key in the Navicat for mysql trigger
how to update specific row in on update key in the Navicat for mysql trigger   Blockquote insert into two(name, date) select name, curdate() from one on duplicate key update name=values(name
Dynamically added Row is Invisible in another javascript function..?
Dynamically added Row is Invisible in another javascript function..?  I have table as below, I need to create 5 default rows, ( this is fine with below code)..but when add row its creating row in a table, but the created row
getting result in table dynamically - Struts
getting result in table dynamically  How do i get result in tabular format dynamically using our own tags
Insert a row in 'Mysql' table using JSP Code
Insert a row in 'Mysql' table using JSP Code In this section, we... between your Tomcat server & Mysql database Table. Code to insert row in Mysql...;/html>ADS_TO_REPLACE_27 OUTPUT : After inserting row in table
How to change the data in the table dynamically ?
How to change the data in the table dynamically ?  This is my code. I... then the data displayed in the table below should get sorted dynamically in this jsp page... datastore = DatastoreServiceFactory.getDatastoreService(); Query q = new Query
insert data 50 row *column into 300 row *column by using xls sheet data (50 row *column) are given in xls sheet
insert data 50 row *column into 300 row *column by using xls sheet data (50... with 300 row and 300 column,this is master table we have input data 50 row and 50...,this is client table, 2- Now we want to copy or insert data into master table from client
Insert Records in Table
Insert Records in Table       The Insert data in Table is used to insert  records or rows into the table in database. The Syntax used to insert records into a table
updating rows which contains same id, different value for each row
updating rows which contains same id, different value for each row  Student table: sid name age 3... 30 From the above table we can identify that 4 rows with sid 1 and 3
how to insert one table to anothere table
how to insert one table to anothere table  i have insert the record one table then i retrve the value of that table i insert one value at a time
Table maximum Row count - JDBC
Table maximum Row count  Dear friends I want to select maximum time entry Status from db. for example : Status : 3 4 6 8 3 5 7 5 5 7 5 3 4 5 2 5 1 my output will be 5 means 5 is maximum time
SQL Bulk Insert
; SQL Bulk Insert is performed when you insert a records  or row to a table... an example from 'SQL Bulk Insert'. To understand and grasp example we create a table...()); Insert Data Into Stu_Table The bulk values of  records
Highlight a corresponding table row - Struts
Highlight a corresponding table row  I have 2 jsps... the table being displayed with rows having links in them(paged display of the table due to huge data) 2.wen klik on the link it leads to Return.jsp 3.now wen
Deleting a Row from SQL Table Using EJB
Deleting a Row from SQL Table Using EJB   ... to delete a row from the SQL Table. Find out the steps given below that describes how to delete a particular row from the database table using EJB. The steps
Write a query to insert a record into a table
Write a query to insert a record into a table  Write a query to insert a record into a table   Hi, The query string is as follows-ADS_TO_REPLACE_1 Insert into employee values ('35','gyan','singh'); Thanks
What?s the maximum size of a row in SQL table?
What?s the maximum size of a row in SQL table?  What?s the maximum size of a row in SQL table?   Hi, The maximum Row Size is 8060 Bytes in a sql table.ADS_TO_REPLACE_1 Thanks
insert excel sheet into mysql as a table
insert excel sheet into mysql as a table  sir, i want to import an excel sheet into mysql5.0 database as in the table format using tomcat 6.0 by jsp
Deleting row and column from a table
Deleting row and column from a table  In this program ,we delete row and column of a table. First we create connection to a database using connection interface and java driver. After it we can delete row using "delete
Java Program to insert a row in the same sheet of excel file
Java Program to insert a row in the same sheet of excel file  Java program to insert a row in the same sheet of excel file using poi package in java
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  Hi, how to dynamically increase size of list... insert new course in a table.. It should be seen in my list box..ADS
JavaScript add row to table
JavaScript add row to table      ... will get the table containing the columns Name and Address and a button 'Add row'. On clicking the button, a new row will be added to the table. ADS_TO_REPLACE_1
how to insert value in dynamic table
how to insert value in dynamic table  i am creating a project... a dynamic table for every company.but whenever i'm inserting values to the company...=con.prepareStatement("insert into "+company+year+"(firstname,lastname,email
Table's row elimination based on option choosen
Table's row elimination based on option choosen  I have a drop down with yes and no option.if i select yes in a table 2 new rows are shown and if i select no another question in row appears but the space occupied by the question
delete row from a table using hibernate
delete row from a table using hibernate  //code in java file String hql="delete from CONTACT c where ID=6"; Query query=session.createQuery(hql); //error when executing above code CONTACT is not mapped
Retrieve database from the table dynamically in jsp from oracle using servlet
Retrieve database from the table dynamically in jsp from oracle using servlet  Sir, I have created a table in oracle using eclipse, and added few columns dynamically. I want to retrieve the table with all columns dynamically
Create After Insert Trigger in SQL
AFTER insert ON stu_table FOR EACH ROW BEGIN INSERT into stu_log...', an insert trigger is fired and performed for each rows in the table. Once..._TO_REPLACE_3 The Query create a  trigger stu_insert on table
How to add dropdown list in a row of a sort table applet?
How to add dropdown list in a row of a sort table applet?  How to add dropdown list in a row of a sort table applet
Updating rows who has same id with different values for each row from java program
Updating rows who has same id with different values for each row from java program  Here is my requirement, Following is a table which contains 5 rows with same id. student table: sid sname age 2 aruna 25 2
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  hi all, how can i insert elements into java script list box retrieving from Database. whenever I insert any element in the Db
Delete and add row from Table View iPhone
Delete and add row from Table View iPhone In this tutorial will learn how to delete and also how to add row into the table view iPhone, with the help of edit... of items (or rows) that may be divided into sections. Each row may display strings
The INSERT INTO Statement
of data into the table. To insert records into a table, just write the key word INSERT INTO 'table name', and write a list of column names separated by commas...; INSERT INTO 'table_name'('field_name', 'field_name'. . .) VALUES ('field_value
How to search the selected item in row table using radia button in JSP?
How to search the selected item in row table using radia button in JSP?  How to search the selected item in row table using radia button in JSP
dynamically created links id from mysql table is not getting
dynamically created links id from mysql table is not getting  guys, i'm trying to access dynamically called attributes from mysql table as a link... the last attribute from the table. below is my code <%@page contentType="text/html

Ads