Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Insert specific fields into table dynamically for each row.

Have Programming Question? Ask it here!
 
 
 


nataraju
Insert specific fields into table dynamically for each row.
2 Answer(s)      3 years and 4 months ago
Posted in : JSP-Servlet


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.


Advertisement
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? Please clarify this. Thanks
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
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
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... the connection we are going to delete a specific row from the table. If the 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
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
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...); if(count>0){ System.out.println("Deleted Specific Row in the table
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
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
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
getting result in table dynamically - Struts
getting result in table dynamically  How do i get result in tabular format dynamically using our own tags
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
Insert a row in 'Mysql' table using JSP Code
Insert a row in 'Mysql' table using JSP Code In this section, we...; Mysql database Table. Code to insert row in Mysql table : databaseinsertion.jsp... : After inserting row in table ,the following message will display 
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
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
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
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
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
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
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. Thanks
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
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
SQL Bulk Insert
; SQL Bulk Insert is performed when you insert a records  or row to a table... Bulk Insert'. To understand and grasp example we create a table 'Stu_Table..._Name varchar(15),Stu_Class()); Insert Data Into Stu_Table
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.  Here is the code
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- Insert into employee values ('35','gyan','singh'); Thanks
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
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
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
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
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
fields
fields  hi.create a class named librarybook that contains fields to hold methods for setting and getting a librarybooks title,author, and page count
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
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
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
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
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
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
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
for each
for each  Sir, is it possible to write bubble sort in java using for each loop ? or any two related nested loops using for each? Thanks in advance
How to get table row contents into next jsp page
code retrieve data from database and display in the html table. At each row...How to get table row contents into next jsp page  Hi, I have a 30... page.But the problem is how do i get the selected radio button table row
How to add a column with checkboxes for each record in my table in JSP
How to add a column with checkboxes for each record in my table in JSP   Hi, Could you please explain it to me how I can add a column with check boxes for each record in my table in JSP? Also, I want to figure out a way
how to make seperate view count for each row while clicking view button
how to make seperate view count for each row while clicking view button  I am getting problem with view count when i click view button the seperate count should be happen for each row here is my code ** Tabledata.jsp <
Advertisements
 

 

 

DMCA.com