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



Home Answers Viewqa Java-Beginners How to insert multiple checkboxes into Msaccess database J2EE using prepared statement

Have Programming Question? Ask it here!
 
 
 


Karen
How to insert multiple checkboxes into Msaccess database J2EE using prepared statement
3 Answer(s)      4 years and 3 months ago
Posted in : Java Beginners


Dear Experts,

Tried as I might looking for solutions to resolve my Servlet problem, I still can't resolve it. Hope that you can share with me the solutions.

In my html form which has a post, I have the following code:-

<td><h3><b>Subjects to be tutored :</b></h3></td>
<table width="800" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #CFE5FF; background:#fff;">
<tr> <th>Lower Primary</th>
<td><input type="checkbox" name="txtsubjects[]" value="English">English
<input type="checkbox" name="txtsubjects[]" value="Chinese">Chinese
<input type="checkbox" name="txtsubjects[]" value="Math">Math
<input type="checkbox" name="txtsubjects[]" value="Science">Science </td>
</tr>
</table>

And in my servlet, I'm stuck because when I'm trying to use the prepared statement to do the checked boxes part, I'm not sure how to go about doing it.

What I did is :-

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:user");
String strSubjects[] = request.getParameterValues("txtsubjects");
int subjects = strSubjects.length;

strCreateRecordSQL = "INSERT INTO Parents";
strCreateRecordSQL += "(strID, strFullName,strEmail,strAddress,"
+ " strLocation, strContact, strType, strSubjects, "
+ " strFrequency, strTutorspref, stBudget, StrRemarks) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
ps = con.prepareStatement(strCreateRecordSQL);
//Fill up the blanks (?) in the SQL with the form data
ps.setString(1, strID);
ps.setString(2, strFullName);
ps.setString(3, strEmail);
ps.setString(4, strAddress);
ps.setString(5, strLocation);
ps.setString(6, strContact);
ps.setString(7, strType);
if (strSubjects != null){
for(int i=0; i <strSubjects.length; i++){
ps.setString(8, strSubjects[i]);
}
}

I'm not sure how to do the part at ps.setString there and also do I have to create different columns for strSubjects because if the user tick all the 4 subjects it will have to go into 4 separate columns right.

Advertisement
View Answers

May 10, 2010 at 4:24 PM


Hi Friend,

There is no need to create different columns for different subjects, you can insert the multiple subjects in one column.

Try the following code:

1)checkbox.jsp:

<html>
<form method="post" action="../Insert">
<table>
<tr><td>Languages</td><td><input type="checkbox" name="lang" value="Hindi">Hindi<input type="checkbox" name="lang" value="English">English<input type="checkbox" name="lang" value="French">French<input type="checkbox" name="lang" value="German">German</td></tr>
<tr><td><input type="Submit" value="Submit"></td></tr>
</form>
</html>

2)Insert.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class Insert extends HttpServlet{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String checkValues[]=req.getParameterValues("lang");
String value="";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn =DriverManager.getConnection("jdbc:odbc:access");
for(int i=0;i<checkValues.length;i++){
value+=checkValues[i]+" ";
}
Statement stmt = conn.createStatement();
int j=stmt.executeUpdate("insert into Student(Subjects) values('"+value+"')");
out.println("Inserted successfully");
}
catch(Exception e){}
}
}

Thanks


May 12, 2010 at 4:38 PM


Dearest Guru Deepak,

I want to THANK YOU so much for your help towards my question.

After looking again and again my program, I have corrected a few more errors, mainly in the jsp portion and it's working fine now - meaning, the data goes to my Ms Access Database.

You are the GREATEST !!! You have made Java Programming not as fearful as it is, not as a MYTH.

Thank you. I'll now work on the filtering part....Thank you. You make it possible for me to continue on this project. You don't know how much it meant to me. Bless you.


November 9, 2010 at 2:59 PM


Hi Dear Karen You can also contact with me about Java Servlet Programming

Bintu Chaudhary...



Related Tutorials/Questions & Answers:
How to insert multiple checkboxes into Msaccess database J2EE using prepared statement - Java Beginners
How to insert multiple checkboxes into Msaccess database J2EE using prepared... statement to do the checked boxes part, I'm not sure how to go about doing... for different subjects, you can insert the multiple subjects in one column
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... Insert data in mysql database through jsp using prepared statement...; <HEAD> <TITLE>insert data using prepared statement </TITLE>
Advertisements
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... link: http://www.roseindia.net/jsp/prepared-statement-query.shtml   
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...;Please visit the following link: http://www.roseindia.net/jsp/prepared-statement
JDBC Prepared Statement Insert
JDBC Prepared Statement Insert   ... Statement Insert. In this Tutorial  the code describe the include a class... the code.set String ( )  - This is a method defined in prepared Statement class
how to update combobx's selected value to database with respect toselected multiple checkboxes
how to update combobx's selected value to database with respect toselected multiple checkboxes   suppose this if form1.jsp in which i am going to display records from database out.println("<tr><td>"+"<input type
how to create bar chart in jsp using msaccess database
how to create bar chart in jsp using msaccess database  type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array  i am using netbeans 7.0 ,with struts 1.3.8 and i want to insert multiple images in mysql database ,with use
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
JDBC: Insert Record using Prepared Statements
JDBC: Insert Record using Prepared Statements In this section, you will learn how to insert row using Prepared Statements. Insert Record  ...(); } } } Output : Insert Record using Prepared Statement
JDBC: Select Records using Prepared Statement
JDBC: Select Records using Prepared Statement In this section, you will learn how to retrieve records of table using Prepared Statement. Select Records   : Prepared Statement is precompiled SQL Statements which are stored
how to insert multiple columns of a single row into my sql database using jsp
how to insert multiple columns of a single row into my sql database using jsp  hi sir, how to insert multiple columns of a single row into my sql database using jsp. when i click ADD ROW,rows are added.when i click submit
JDBC Insert Prepared Statement
; } JDBC Insert PreparedStatement PreparedStatement represents a precompiled SQL statement. It is alternative to Statement At first Create named student a table in MySQL database as CREATE TABLE `student` ( `rollno` int(11
Update Record using Prepared Statement
JDBC: Update Record using Prepared Statement In this section, you will learn how to update row using Prepared Statements. Update Record   : Prepared statement is good to use where you need to execute same SQL statement
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
Prepared statement JDBC MYSQL
Prepared statement JDBC MYSQL  How to create a prepared statement in JDBC using MYSQL? Actually, I am looking for an example of prepared statement.   Selecting records using prepared statement in JDBC
Hibernate Prepared Statement
This section contain how prepared statement works in hibernate
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  thanks for reply, that code i can use but i get the below error, pls help me message description The server encountered an internal error () that prevented it from
fetch and insert multiple rows into mysql database using jsp servlet
fetch and insert multiple rows into mysql database using jsp servlet  ... jsp form and want inserting it into my mysql database table. but i am having a problem to insert multiple rows into database using a single insert query
JDBC: Delete Record using Prepared Statement
JDBC: Delete Record using Prepared Statement In this section, we will discuss how to delete row of a table using Prepared Statements. Delete Record ... of student whose roll_no is 3  using prepared statement. package jdbc
PDO Prepared Statement
statements and how to use it using PDO. Sometimes it is more commodious for us to use a Prepared Statement for sending SQL statements to the database..., using this we can reduce the execution time. The prepared statement can
Inserting Records using the Prepared Statement
to learn how we will insert the records in the database table by using... Inserting Records using the Prepared Statement  ... records example using prepared statement! Enter movie name: Bagban
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
Updating multiple value depending on checkboxes
Updating multiple value depending on checkboxes  Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes..? please answer if any one knows as soon as possible
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 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..."); Statement st=con.createStatement(); int i=st.executeUpdate("insert
checking index in prepared statement
links: http://www.roseindia.net/jdbc/prepared-statement-insert.shtml http://www.roseindia.net/jdbc/insert-prepared-statement.shtml Thanks...checking index in prepared statement  If we write as follows: String
prepared statement
prepared statement  plese give me a code that have preparedstatement interface and uses a select query having condition date="s"; where s is the date, but this date parameter passed as the string
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="font&colors.css" rel="stylesheet" type="text/css"> <p></p>
difference between prepared statement and statement
difference between prepared statement and statement  i mean in prepared statement we write insert command as INSERT INTO tablename VALUES(?,?) but in normal statement we write insert into tablename(jtextfiled1.gettext
how to display selected checkboxes dynamically using jsp
how to display selected checkboxes dynamically using jsp  Hi friends i have a requirement that : in my JSP page i have radio buttons followed by the DB fields..when i click SUBMIT button,if the field(or record
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 have one task to do soft parsing tl asked to do callable statement,stored
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 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
prepared statement in sqlite
prepared statement in sqlite  How to writer "prepared statement in sqlite" ?   $register->bind_param('ssssssis', $name, $username, $password, $email, $security_answer, $date, $user_level, $security_question); S
want to ask how to update data for runtime selected multiple checkboxes
want to ask how to update data for runtime selected multiple checkboxes  HI I have one problem I have fetched value from oracle database into grid... have checkboxes for each record when I will select more than one checkboxex
How to insert dynamic textbox values into database using Java?
How to insert dynamic textbox values into database using Java?  Hi I am trying to insert dynamic textbox values to database, my jsp form have 2... of dynamic textboxes with Name and Address will display....Now I want to Insert
Facing Problem to insert Multiple Array values in database - JSP-Servlet
facing the problem while inserting the data in database. iam using the MsAccess Database My Database structure is Like iam using tow tabel ,CustomerDetails...Facing Problem to insert Multiple Array values in database  Hai
Set Timestamp by using the Prepared Statement
example by using the Prepared Statement! 1 row(s) affected) Database... Set Timestamp by using the Prepared Statement... will teach how to set the Timestamp in database table by using
prepared statement in for loop - JDBC
prepared statement in for loop  Hi all, I am reding data from a jsp page and inserting into a table. For this i am using prepared statement...)poForm.get("PONO"); String strQuery1 = "Insert into PurchaseOrder values
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
Executing Prepared Statement
; } Executing Prepared Statement Prepared Statement represents the pre... is no-parameter prepared statement example. Example- At first create table named student in MySql database and inset values into it as. CREATE TABLE student ( RollNo
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
Insert Date using Statement - Development process
Insert Date using Statement   Hi, plz send me code for Storing system date using statement instead of preparedstatement. Thanks Prakash  Hi Friend, Try the following code: Thanks
How to insert and retreive an image in mysql database using spring mvc framework???
How to insert and retreive an image in mysql database using spring mvc framework???  I ve solved this problem based on the Product Search Application. Those who need this concept and code segment kindly copy it. Thanks and All
Count Records using the Prepared Statement
Count Records using the Prepared Statement  ... to count all records of the database table by using the PreparedStatement... will know that how many records in a database table then you get easily with the help
to write an SQL query using insert statement
to write an SQL query using insert statement  I need to write an sql query for the below using InSERT command.pls help. Insert 5-star ratings by James Cameron for all movies in the database. Leave the review date as NULL
Usage of setDate() in prepared Statement - JDBC
Usage of setDate in prepared Statement  Hi, I have created a jsp...() of prepared statement,the following error is displayed: setDate() not available in prepared statement. Basically, I need to accept the date dynamically
Retriving multiple values of checkboxes in struts
Retriving multiple values of checkboxes in struts  how to retrive multiple values of checkboxes of jsp in action class   JSP Retrieve checkbox values 1)checkbox.jsp: <html> <body> <form method="post
 

 

 

DMCA.com