0 Replies - 1674 Views - Last Post: 12 May 2014 - 05:20 AM

#1 shyamsundarjava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-May 14

INSERT Multiple values of checkbox into database using JSP Servlet?

Posted 12 May 2014 - 05:20 AM

Hello, As I am new in java, JSP and DATABASE...


                   

  <form action="Insert_Values_Servlet" method="post">
 <label><strong>Title</strong></label> 
                                <input type="text" name="Title" placeholder="max 50 characters"/><br>

                    <label><strong>Profession</strong></label>
                               <input type="text" name="Profession" placeholder="Ex.Manager"/> <br>

<input type="checkbox" value="LifeStyle" id="slideOne" name="check" />
		<label for="slideOne">LifeStyle</label><br />

		<input type="checkbox" value="Health-care" id="slideOne2" name="check" />
		<label for="slideOne2">Health-care</label><br />
	
		<input type="checkbox" value="Education" id="slideOne3" name="check" />
		<label for="slideOne3">Education</label><br />
	
		<input type="checkbox" value="Real-Estate" id="slideOne4" name="check" />
		<label for="slideOne4">Real-Estate</label><br />
<label><strong>AREA</strong></label>
            <input type="text" name="AREA" placeholder="Ex.Viman Nagar"/><br>
            <label><strong>City</strong></label>
            <input type="text" name="City" placeholder="Ex.Mumbai"/><br>

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


This is my insert.jsp page
I want to insert multiple values into database Including multiple values of checkbox, other values are getting inserted but only problem at selecting multiple checkbox values in same column and radio button value in same column.

---------------------look for servlet page below----------------
  Connection con = null;
        ResultSet rs = null;
        PreparedStatement pst = null;
        int user = 0;
        String User_Id1 = null;
        String Other_Services = "";

        String Title = request.getParameter("Title");
        System.out.println(Title);
        String lang[] = request.getParameterValues("check");// checkbox values
for (int i = 0; i < lang.length; i++) {
            Other_Services += lang[i];
            String Profession= request.getParameter("Profession");
          
           // String Other_Services = request.getParameter("Other_Services ");
              
              //       String Landmark = request.getParameter("Landmark");
            String Area = request.getParameter("Area");
            String City = request.getParameter("City");



          

            try {

                con = DbCon.MCO_Con.connect();
               
                String insertinfo = "INSERT into offer_data (Title,Profession, Other_Services ,Area, City) values(?,?,?,?,?,?)";
                pst = con.prepareStatement(insertinfo);
                //  here other values getting inserted but not for checkbox
                pst.setString(1, Title);
pst.setString(2, Profession);


                pst.setString(3, Other_Services);
                pst.setString(4, Area);
                pst.setString(5, City);
                
                int row = pst.executeUpdate();


Is there any solution to insert this...

By mistake in query I have followed with extra questionmark in following line
This is correctline for inserting 5 values in database
 String insertinfo = "INSERT into offer_data (Title,Profession, Other_Services ,Area, City) values(?,?,?,?,?)";


Is This A Good Question/Topic? 0
  • +

Page 1 of 1