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

 
 


nataraju
Insert specific fields into table dynamically for each row.
3 Answer(s)      2 years 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?

View Answers

May 19, 2011 at 1:16 PM


1)admin.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function editRecord(id){
    var f=document.form;
    f.method="post";
    f.action='edit.jsp?id='+id;
    f.submit();
}
</script>
</head>
<body>

<br><br>
<form method="post" name="form">
<table border="1">
<tr><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";

int sumcount=0;
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="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="done" value="Done" style="background-color:green;font-weight:bold;color:white;" onclick="editRecord(<%=rs.getString(1)%>);" ></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>

2)edit.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<form method="post" action="done.jsp">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String query = "select * from employee where id='"+no+"'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
%>
<tr>
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="address" value="<%=rs.getString("address")%>"></td>
<td><input type="text" name="contact" value="<%=rs.getInt("contactNo")%>"></td>
<td><input type="text" name="email" value="<%=rs.getString("email")%>"></td>
<td><input type="hidden" name="id" value="<%=rs.getString(1)%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<%
}
}
catch(Exception e){}
%>
</table>
</form>

May 19, 2011 at 1:17 PM


continue..

3)done.jsp:

<%@page import="java.sql.*"%>
<%
String ide=request.getParameter("id");
int num=Integer.parseInt(ide);
String name=request.getParameter("name");
String address=request.getParameter("address");
int contact=Integer.parseInt(request.getParameter("contact"));
String email=request.getParameter("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();
st.executeUpdate("update employee set name='"+name+"',address='"+address+"',contactNo="+contact+",email='"+email+"' where id='"+num+"'");
response.sendRedirect("/examples/jsp/admin.jsp");
}
catch(Exception e){
System.out.println(e);
}
%>

May 19, 2011 at 1:59 PM


Thanks for your answer 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.









Related Pages:
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
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
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
delete row
into the html table. Along each table row there is a checkbox consists of id of table. When the user selects the particular checkbox, that row will get deleted...delete row  how to delete row using checkbox and button in php
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
Join tables in the specific database
and tables in a database. Now to retrieve a particular row from a table... is the type of query for retrieving data two or more table in specific database. You... to each other according to common fields but the priority is given to the first
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
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
Create After Insert Trigger in SQL
insert ON stu_table FOR EACH ROW BEGIN INSERT into stu_log(user_id, description..._Insert The Query create a  trigger stu_insert on table 'stu_table'. Whenever we perform insert values into a table 'stu_table', an insert
The INSERT INTO Statement
'. . .); Insert a New Row To insert a new row in a database table we have to write... 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
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
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 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
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 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
row_id
row_id  sir i have created a table my_table with two rows n two column with smillar name in each cell without any primary key , how can i change the first row and third column's name in sql server 2005 , kindly send me the query
row_id
row_id  sir i have created a table my_table with two rows n two column with smillar name in each cell without any primary key , how can i change the first row and third column's name in sql server 2005 , kindly send me the query
Create After Insert Trigger in SQL
_insert AFTER insert ON stu_table FOR EACH ROW BEGIN INSERT into stu_log... on table 'stu_table'. Whenever we perform insert values into a table 'stu_table', an insert trigger is fired and performed for each rows
Selecting All Columns or Specific columns
) Insert the Data in the table: The INSERT statement is used the load the data in the table. Keyword are used in this statement are follows : INSERT - Insert data into the table INTO - Specified the Table name for inserting the data
The INSERT INTO Statement, SQL Tutorial
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
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
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
JavaScript generate dynamic row
dynamically to the table with these 3 fields. Here is the code...JavaScript generate dynamic row In this section, you will learn how to generate dynamic row using JavaScript. Here a row contain 3 fields(2 textfields,1 text
Dynamic row genertion in javascript? - JSP-Servlet
Dynamic row genertion in javascript?  Hi roseindia, I want coding in javascript to add a dynamic row in jsp..This row contain 3 fields(2 textfields,1 textarea).Every time if i click add button have to add dynamically
Mysql Trigger After Insert
-> AFTER insert ON employee -> FOR EACH ROW -> BEGIN... perform an insert a records or rows to the table. Understand with Example... rows affected (0.05 sec) Insert data into table:- Insert into add the records
insert data in the database using checkbox
each row but the problem is that i am not fetching data in any textboxes so how should i insert only checked data into database on submission.   We...insert data in the database using checkbox  i am fetching data from
Inserting a row using PreparedStatement
INSERING A ROW USING PREPAREDSTATEMENT If you want to execute a statement many time , "PreparedStatement " reduces execution time. Unlike a "... statement and supply it with different values each time you execute
PHP Insert Value
Insertion of data into table: We will study in this tutorial how to insert... to insert values into respective fields. To describe or to know the design...'); Now to insert values into table:   ii)    Using WAMP
Difference between Normal Insert and BLOB insert
), DisplayImage (image). Table has 2 rows for first row i have written insert into Image values(1,'Libraries\Pictures\Lotus.jpg') and 2nd row as INSERT INTO [dbo...Difference between Normal Insert and BLOB insert  I have sql database
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 
Create Before Insert Trigger in SQL
ON stu_table FOR EACH ROW BEGIN set new.total = new.sub1 + new.sub2... before we insert the value into the table. Understand with Example The given..._Insert' on table stu_table. The Before Insert ON  trigger is fired
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
Cross Join Tables in a Specific Database
tables as a Cartesian product of set theory in mathematics. Each row will get multiplied by other rows. If one table has three rows and the second row has two... will be performed between two tables. Both tables hold some specific fields
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
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
Retrieving specific data from excel
contain heading for each row written in bold and the student details...()) { Row row = rowIterator.next(); //For each row, iterate through...Retrieving specific data from excel  Hello everyone, i have written
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
Mysql last row
; ); Query to insert data into Table named employee1:- mysql>insert into employee1 values(01,'Girish','2008-12-20'); Query OK, 1 row...'); Query OK, 1 row affected (0.02 sec) mysql>insert into employee1 values(03
jdbc insert
jdbc insert  Hi , i want to insert a declared integer variable into a mysql table through jdbc. how to insert that. help me with query... thanks... a table there. After creating a table in database, it insert a rows in the database
PHP SQL Table
statement. The Table "emp_table" create with three fields, "emp... PHP SQL Table       PHP SQL Table is used to create table in PHP. To create a table in PHP
MySQL PHP Insert
affected (0.13 sec) Query for inserting data in table: The Query insert into is used to add the records to the table 'MyTable'. mysql> insert...) mysql> insert into MyTable values(02,'A','21000'); Query OK, 1 row affected

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.