insert data in the database using checkbox

insert data in the database using checkbox

i am fetching data from the database using servlet on the jsp page and there is checkbox corresponding 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.

View Answers

April 17, 2012 at 4:02 PM

We are providing you the code where we have specified only three fields bookid,author and title in the database. Follow these steps to update these fields:

1) Create book.jsp

<%@page import="java.sql.*"%>

<form name=myname method=post action="edit.jsp">
<table border="1">
<tr><td></td>
<td><b><u>bookid</u></b></td>
<td><b><u>Author</u></b></td>
<td><b><u>title</u></b></td>
</tr>
<%try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://192.168.10.112:3306/mysql","root";, "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
rs = st.executeQuery("select * from book");
int i=0; while(rs.next()){ %>
<tr><td><input type="checkbox" name="check<%=i%>" value=<%= rs.getString("bookid") %>></td>
<td><%= rs.getString("bookid") %></td>
<td><%= rs.getString("author") %></td>
<td><%= rs.getString("title") %></td>
</tr><%
i++;
}
}catch(SQLException e){ System.out.println(e.getMessage()); } %>
</table>
<input type="submit">
</form>

2) Create edit.jsp

<%@page import="java.sql.*"%>

<%String id[]= new String[10];
for(int i=0;i<10;i++){
id[i]=request.getParameter("check"+i);
out.println(id[i]);
}
%>

<form name=myname method=post action="update.jsp">
<table border="1">
<tr>
<td><b><u>bookid</u></b></td>
<td><b><u>Author</u></b></td>
<td><b><u>title</u></b></td>
</tr>
<%try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://192.168.10.112:3306/mysql","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
for(int a=0;a<10;a++){
rs = st.executeQuery("select * from book where bookid='"+id[a]+"'");
while(rs.next()){ %>
<tr>
<td><input type="text" name="bid" value="<%= rs.getString("bookid") %>"></td>
<td><input type="text" name="auth" value="<%= rs.getString("author") %>"></td>
<td><input type="text" name="tit" value="<%= rs.getString("title") %>"></td>
</tr><%
}
}
}catch(SQLException e){ System.out.println(e.getMessage()); } %>
</table>

<input type="submit">
</form>

April 17, 2012 at 4:04 PM

continue........

3)Create update.jsp

<%@page import="java.sql.*"%>
<%
String d[] =request.getParameterValues("bid");
if(d !=null) {
for(int i=0;i<d.length;i++) {
out.println(d[i]);
}
}
String name[] =request.getParameterValues("auth");
if(name !=null) {
for(int i=0;i<name.length;i++) {
out.println(name[i]);
}
}
String title[] =request.getParameterValues("tit");
if(title !=null) {
for(int i=0;i<title.length;i++) {
out.println(title[i]);
}
}
%>
<%
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://192.168.10.112:3306/mysql","root", "root");

Statement st=null;
st=conn.createStatement();
for(int a=0;a<10;a++){
String book_id=d[a];
String author=name[a];
String tit=title[a];
st.executeUpdate("update book set author='"+author+"', title='"+tit+"' where bookid='"+book_id+"'");
}
}
catch(Exception e){
e.printStackTrace();
}
%>

As we have update 3 fields in the database,in the same way you can update all the fields.









Related Tutorials/Questions & Answers:
insert data in the database using checkbox
insert data in the database using checkbox  i am fetching data from the database using servlet on the jsp page and there is checkbox corresponding... should i insert only checked data into database on submission.   We
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's...;   Here is a simple jsp code that insert the selected checkbox values
Advertisements
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  how to insert check box value to the database using jsp my code is <link href...; <td align="center"> <input type="checkbox
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's package. where the admin will select the activities to insert in the PACKAGE table. I
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
how to insert data in database using html+jsp
how to insert data in database using html+jsp  anyone know what... and database name. Here machine name id localhost and database name..."; // declare a connection by using Connection interface
i need program to insert data in database using javascript
i need program to insert data in database using javascript  please help me
using ajax i want to insert data into oracle database
using ajax i want to insert data into oracle database  i would like to insert/update/select/delete from jsp to oracle database using ajax? please send a code for this iam using oracl database thank you
how to insert data from database using oops concepts - Development process
how to insert data from database using oops concepts  Hi, How to insert data from database using oops based concepts.please write the code... the following code: import java.sql.*; class Insert{ public static String url
How to insert data from textfields into database using hibernate?
How to insert data from textfields into database using hibernate?   try{ Session session = HibernateUtil.getSessionFactory().openSession...); System.out.println("Successfully data insert in database"); tx.commit
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 Insert Data Delete Data ThanksADS_TO_REPLACE_2
insert checkbox in cell using POI api in java
insert checkbox in cell using POI api in java  I need to insert checkbox in excel cell using POI and java. Any one help me on this. Ashok S
insert data into database
insert data into database  hi,thanks for reply just i am doing... and studentmaster is the database table name. i am using same details. Now give the data into the jsp page that data stored into the database.Here the error
Problem insert data into database using servlet n javabean - Java Beginners
Problem insert data into database using servlet n javabean  I created a servlet for registration proses I got a problem compiling my servlet... = conn.createStatement(); rs = stmt.executeUpdate("INSERT INTO login(name,userid
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base syntax which i m using is like:- java class
database is connected but not insert the data
database is connected but not insert the data  hi, i am getting connected to database.Retrive the data also but cannot insert the data into database. i am using msaccess2007.my inserstudententry.jsp code is follows,pls help me
Insert excel file data into database Using Java Programming
Insert excel file data into database in Java Program In this PHP tutorial section, you will learn how to insert excel file data into the database. We have... excel file data into Database Using java programming: import java.io.
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
callable statement,stored procedure for insert data and also for update data into oracle database using jsp  iam a fresher newbie to softparsing i... procedure for inserting data into oracle database as bind variable and same
Insert data in mysql database through jsp using prepared statement
Insert data in mysql database through jsp using prepared statement...; This is detailed jsp code that how to insert data into database by using prepared statement...*" %>  <HTML> <HEAD> <TITLE>insert data using
insert date into database using jsf
insert date into database using jsf  Hello I need a simple example of source code to insert a date into a database using jsf what do I have to put in backing bean and page jsf ( i need juste a date ) thanks
insert data into database
insert data into database  type Exception report message...)Go to the start->Control Panel->Administrative Tools-> data sources. 2... selecting the driver, click finish button. 4)Then give Data Source Name
How to insert multiple drop down list data in single column in sql database using servlet
How to insert multiple drop down list data in single column in sql database using servlet  i want to insert date of birth of user by using separate drop down list box for year,month and day into dateofbirth column in sql server
To insert maximum number of data in database.
To insert maximum number of data in database.  how to change string data type into clob data type in jsp   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/jdbc/insert-clob
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
how to read data from excel file through browse and insert into oracle database using jsp or oracle???  sir.. i have number of excel sheets which... a browse button which can upload a excelfile and after uploading the data should
Insert XML file data to database
Insert XML file data to database In this tutorial, you will learn how to insert the xml file data to database using dom parser. You all are aware of XML... to read the xml file data and save the values of an XML file to a Database
Insert file data into database
Insert file data into database In this section, you will learn how to insert.... Now to insert this data into the database, we have established a database connection. Then using the insert query, we have inserted whole file data
Insert Data into Database Using Hibernate Native SQL
Insert Data into Database Using Hibernate Native SQL... to insert data into database. Native SQL is handwritten SQL for all database operations like insert, update, delete and select.  Hibernate provides
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it   I have tried the following code Database creation: create database studentdb; create table stu_info ( ID int not null auto
Insert text file data into Database
Insert text file data into Database In this section, you will learn how to insert the text file data into the database. For this purpose, we have created... the data to the ArrayList. This list is then iterated through the Iterator
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it   I have tried the following code Database creation: create database studentdb; create table stu_info ( ID int not null auto
Question about "Insert text file data into Database"
Question about "Insert text file data into Database"  Hey I was reading the tutorial "Insert text file data into Database", (awesome btw), and noticed that both a FileInputStream, a DataInputStream and a BufferedReader
code for selected checkbox columns data from database
code for selected checkbox columns data from database  in my page iam getting all column names of a particular table with checkboxes. when iam select one or more checkboxes i have to get data of that selected columns only. what
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database... = connection.prepareStatement("insert into file(file_data) values(?)"); fis = new
Insert data in Excel File from Database using JSP
Insert data in Excel File from Database  using JSP ... will retrieve the data from database, create an excel file and data insert... developed a application to insert data  in excel file from database in JSP. We
insert name city and upload image in database using mysql and jsp
insert name city and upload image in database using mysql and jsp   insert name city and upload image in database using mysql and jsp
what is the jsp coding to insert a data in database tables
what is the jsp coding to insert a data in database tables  Dear Sir, I Want to know the coding for insert the data from jsp to oracle database.. my... that insert the form values to MySQL database. 1)register.jsp: <html> <form
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc  â?¢ Create a Registration Form with 10 input fields using HTML and get those inputs using JSP and insert those inputs into database using JDBC.   Here is a jsp code
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc  â?¢ Create a Registration Form with 10 input fields using HTML and get those inputs using JSP and insert those inputs into database using JDBC.   Here is a jsp code
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc  â?¢ Create a Registration Form with 10 input fields using HTML and get those inputs using JSP and insert those inputs into database using JDBC.   Here is a jsp code
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc  â?¢ Create a Registration Form with 10 input fields using HTML and get those inputs using JSP and insert those inputs into database using JDBC.   Here is a jsp code
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
insert data into mysql databse using swing
insert data into mysql databse using swing   Blockquote hi, here is my code, i want code for store data into mysql database when click on submit button from access data from this form, please provide code, import java.awt.
insert name city image in database using mysql and jsp
insert name city image in database using mysql and jsp  how to insert... is an example in jsp that insert name, city and image to database. <%@ page import..."); PreparedStatement psmt=con.prepareStatement("insert into data(name,city,image)"+"values

Ads