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 also have the ACTIVITY table, where it have the PK for every activities.

Here is my code

<%

String pack_id="";
Class.forName("oracle.jdbc.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:orcl", "myvgh", "myvgh");
try{
Statement statement=conn.createStatement();
ResultSet rs=statement.executeQuery("SELECT NVL(MAX(PACK_ID),0) + 1 FROM PACKAGE");
     while(rs.next()){
     pack_id = rs.getString(1);

                      }


  }catch(Exception e1)
  {}
  %> 

                <form>
                <table width="871" height="413" border="0">
                  <tr>
                  <tr>
                                                <td>&nbsp;</td>
                                                <td><input name="pack_id" type="type" value="<%= pack_id %>" size="3" readonly="readonly" /></td>
                                              </tr>
                <td width="124">
                          <p>Package Name</p></td>
                        <td width="29">:</td>
                        <td width="704">
                          <label for="pack_type"></label>
                          <input type="text" name="pack_type" id="pack_type" />
                      </td>
                      </tr>

                      <tr>
                        <td><p>Night and Day</p></td>
                        <td>:</td>
                        <td>
                          <label for="pack_day"></label>
                          <input type="text" name="pack_day" id="pack_day" />
                                          </td>
                      </tr>

                      <tr>
                        <td><p>Meal</p></td>
                        <td>:</td>
                        <td>
                          <label for="pack_meal"></label>
                          <input type="checkbox" name="pack_meal" id="breakfast" />Breakfast
                          <input type="checkbox" name="pack_meal" id="Lunch" />Lunch
                          <input type="checkbox" name="pack_meal" id="Dinner" />Dinner

                          </td>
                      </tr>

                      <tr>
                        <td><label for="activity8"> Activity<br />
                        </label></td>
                        <td>: </td>
                        <td><input name="activity7" type="checkbox" id="act_name" name="act_name" value="caltural_night" />
                        Cultural Night
                             <input name="activity" type="checkbox" id="act_name" name="act_name" value="batik_painting" />Batik Painting </td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td><input type="checkbox" id="act_name" name="act_name" value="pounding_rice" />Pounding Rice 
                          <input type="checkbox" id="act_name" name="act_name" value="fishing" />Fishing </td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td><input type="checkbox" name="act_name" id="act_name" value="kite_making" />
                        Kite Making
                           &nbsp; <input type="checkbox" id="act_name" name="act_name" value="gagau_ikan" />&quot;Gagau Ikan&quot;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td><input type="checkbox" id="activity12" name="act_name" value="iks_visit" />
                        IKS Visit
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                         <input type="checkbox" id="activity13" name="act_name" value="bbq" />BBQ</td>
                      </tr>
                      <tr>
                        <td>Price (RM)</td>
                        <td>:</td>
                        <td>
                          <label for="pack_price"></label>
                          <input name="pack_price" type="text" id="pack_price" size="12" />
                        </td>
                      </tr>
                      <tr>
                        <td>Max Person</td>
                        <td>:</td>
                        <td>
                          <label for="pack_max"></label>
                          <input name="pack_max" type="text" id="pack_max" size="7" />
                        </td>
                      </tr>
                      </table>
                      <div align="center">
                        <input type="submit" name="submit2" id="submit2" value="Submit" />
                        <input type="submit" name="clear2" id="clear2" value="Clear" />
                     </div></td>
                  </tr>
                  </table>
                  </form>
View Answers

July 12, 2012 at 5:08 PM

Here is a simple jsp code that insert the selected checkbox values into database.

1)checkbox.jsp:

<html>
<body>
<form method="post" action="insertmultiple.jsp" >
Select Languages:<br>
<input type="checkbox" name="lang" value="C/C++">C/C++<br>
<input type="checkbox" name="lang" value="JAVA">Java<br>
<input type="checkbox" name="lang" value="C#">C#<br>
<input type="checkbox" name="lang" value="PERL">PERL<br>
<input type="checkbox" name="lang" value="PYTHON">PYTHON<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

2)insertmultiple.jsp:

<%@page import="java.sql.*"%>
<%
String languages="";
String lang[]=request.getParameterValues("lang");
for(int i=0;i<lang.length;i++){
    languages+=lang[i]+" ";
}

        try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
        Statement st=con.createStatement();
        int i=st.executeUpdate("insert into student(languages) values('"+languages+"')");
        out.println("Data is successfully inserted into database.");
        }
        catch(Exception e){
        System.out.println(e);

} %>


July 12, 2012 at 5:53 PM

Thank you for the answer. I've tried to edit this code. But how to insert another column in the database?

I have this error org.apache.jasper.JasperException: java.lang.NullPointerException

Here is my createPackageProcess.jsp codes

<body>
    <%

            String pack_id = request.getParameter("pack_id");
            String pack_name = request.getParameter("pack_name");
            String pack_day = request.getParameter("pack_day");
            String pack_price = request.getParameter("pack_price");
            String pack_max = request.getParameter("pack_max");
                    String pack_act = request.getParameter("pack_act");

                    String meal="";
                    String pack_meal[]=request.getParameterValues("pack_meal");
                    for(int i=0;i<pack_meal.length;i++){
                        meal+= pack_meal[i]+" ";
                    }
                    String act="";
                    String act_name[]=request.getParameterValues("act_name");
                    for(int i=0;i<act_name.length;i++){
                        act+= act_name[i]+" ";
                    }
%>        


<% 

       String addPackage= "INSERT INTO ACTIVITY VALUES('"+pack_id+"','"+pack_name+"','"+pack_day+"','"+pack_meal+"','"+pack_act+"',"
               + "'"+pack_price+"','"+pack_max+"')";

            Statement statement = conn.createStatement();



            statement.executeUpdate(addPackage);



            %>
            <script language="javascript">
                 alert("Successfully Inserted!");


                 window.location.href = "adminCreatePackage.jsp";
            </script>

       }
       }

        </body>









Related Tutorials/Questions & Answers:
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...="center"> <input type="checkbox" name="pmanager" value="Edit
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 oracle database using jsp? I want to create hotel's...;input name="activity7" type="checkbox" id="act_name" name="act_name" value
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 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
how to get the checkbox value in jsp
how to get the checkbox value in jsp  how to get the checkbox value in jsp?   JSP CheckBox Example - how to get the checkbox value in jsp
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
User Registration Form Using JSP(JspBeans) after that how i can insert in database
User Registration Form Using JSP(JspBeans) after that how i can insert in database   User Registration Form Using JSP(JspBeans) after that how i can insert in database
how to show effect (visual) on jsp page using value from database
how to show effect (visual) on jsp page using value from database  I... i want is when the value in booking status is "booked" then the pictures shown as seats should be displayed red. when the value in booking status
How to insert or delete records in MS access database using jsp - JSP-Servlet
How to insert or delete records in MS access database using jsp  Hi friends please provide me a solution that i insert or delete record from a database using java server pages. I used the microsoft access 2003 database. PlZ
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
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
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
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... be inserted into oracle database.. please help me sir...   hi friend
Insert value of dynamic generated text box in jsp using javascript
Insert value of dynamic generated text box in jsp using javascript  ... that dynamically generated text box value into database at a time without reloading the page what i want is i can insert the multiple columns value generated
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
How to retrieve data from database by using combo box value in jsp?  Hello friend i want use only one jsp page.. but u give 2 pages... I want...; } function showEmp(emp_value) { if(document.getElementById("emp_id").value
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...*" %>  <HTML> <HEAD> <TITLE>insert data using
insert name city image in database using mysql and jsp
insert name city image in database using mysql and jsp  how to insert name ,city and image in database in mysql and jsp   Here is an example in jsp that insert name, city and image to database. <%@ page import
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
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
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
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
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Hii Sir, Lots of thnx to ur reply .I went through both... of selecting value from autocomplete textbox using jquery in jsp from mysql database
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database. ... but was unable to find out exact way to fullfill the solution of selecting value from autocomplete textbox using jquery in jsp from mysql database. Kindly send me
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
To insert attachment file in database in JSP.
To insert attachment file in database in JSP.  I am doing project in JSP. How to insert attachment file in mysql database? Please suggest some solution. Your inputs is valuable to me.   Hi Friend, Visit HereADS
how to delete the access database value in jsp
how to delete the access database value in jsp  i loaded my database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from database
how to delete the access database value in jsp
how to delete the access database value in jsp  i loaded my database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from database
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  For example, In Employee.jsp form, When i click employee id value in combo box...... i already stored combo box values from database. pl
checkbox
checkbox  how to insert multiple values in database by using checkbox in jsp
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all.... Note: I am using only this jsp form.. i do not use
how to update checkbox list in database
how to update checkbox list in database  Issues: i am using... in the database below logic is working fine by using insert command... to update one by one but it's not updating by using below code .it's not adding
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 a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
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 a row in 'Mysql' table using JSP Code
Insert a row in 'Mysql' table using JSP Code In this section, we will discuss about how to insert data in Mysql database using JSP code. Query... between your Tomcat server & Mysql database Table. Code to insert row in Mysql
How to change the checkbox value dynamically.
How to change the checkbox value dynamically.  Hi, I am using struts 1.2 checkbox tag. Requirement is on page load the value must be "true... the page. Then the checkbox is checked instead it have to show unchecked. And even
Insert text into database table using JSP & jQuery
Insert text into database table using JSP & jQuery In this tutorial , the text is inserted into database table using JSP & jQuery. In the below... using "fadeIn" effect. The second JSP page contains code
how to insert array data into sql server using jsp
how to insert array data into sql server using jsp  hello, i have problem to insert array data into my sql server from jsp form. beloW is my code... from form, but not insert into my sql database. try { //String
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
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  Hi Friends, When i click combobox value in jsp form page, it will diplay related value.... I am using only this page.. not get value from another page
How to Insert image and data both together in database in JSP/Servlet ?
How to Insert image and data both together in database in JSP/Servlet ? ..." value="Send File"> </td> </tr> <table> </center>... = connection.prepareStatement("insert into data(Name,City,Img) values('"+nn+"','"+cc
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
how to create database and table using jsp
how to create database and table using jsp  hi frnds...., i want to create database and table in mysql using jsp.... i have an registration form(name... table using jsp code... the table name should be the name of the person
To insert attachment file in database in JSP.
To insert attachment file in database in JSP.  I am doing project in JSP. How to insert attachment file in mysql database? Please suggest some...="submit" value="Send File"> </td></tr> <table> </center>
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 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
How to retrieve data using combo box value in jsp? - JSP-Servlet
How to retrieve data using combo box value in jsp?  Hi freind, I already post this question. I need urgent help from u. pl response me... the following link: http://www.roseindia.net/jsp/comboSelect.shtml Hope

Ads