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



Home Answers Viewqa Java-Beginners how to insert checkbox value into database using jsp
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Izzatie
how to insert checkbox value into database using jsp
1 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


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>

Advertisement
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);

} %>



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...;input name="activity7" type="checkbox" id="act_name" name="act_name" value
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...;   Here is a simple jsp code that insert the selected checkbox values
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 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
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
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 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
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
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
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 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
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
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 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
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
checkbox
checkbox  how to insert multiple values in database by using checkbox in jsp
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
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 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>
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 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 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
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 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
Advertisements
 

 

 

DMCA.com