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



Home Answers Viewqa JSP-Servlet insert multiple selection - Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


siva kumar
insert multiple selection - Java
4 Answer(s)      2 years and 7 months ago
Posted in : JSP-Servlet


how to insert multiple selection values from html into database using servlets


Advertisement
View Answers

April 23, 2012 at 12:26 PM


1)form.jsp:

<html>
<body>
<form method = "post" action = "/Examples/GetParameterValues">
<p>Which of the programming languages you like the most</p>
<select name="lang">
<option value="C/C++">C/C++</option>
<option value="Java">C/C++</option>
<option value=".NET">C/C++</option>
<option value="Perl">C/C++</option>
<option value="Pascal">C/C++</option>
</select>
</form>
</body>
</html>

2) GetParameterValues.java

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

public class GetParameterValues extends HttpServlet{
  protected void doPost(HttpServletRequest request, 
   HttpServletResponse response)
 throws ServletException, IOException {
  response.setContentType("text/html");
  PrintWriter pw = response.getWriter();
  String[] lang = request.getParameterValues("lang");
  for(int i=0; i<whisky.length; i++){
  pw.println("<br>Language : " + lang[i]);
  }
  }
}

3)web.xml file

 <servlet>
  <servlet-name>GetParameterValues</servlet-name>
  <servlet-class>GetParameterValues</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>GetParameterValues</servlet-name>
 <url-pattern>/GetParameterValues</url-pattern>
 </servlet-mapping>


April 23, 2012 at 12:28 PM


Put attribute multiple in select tag. I forget to do that.Anyways change the form.jsp to the following code:

<html>
<body>
<form method = "post" action = "/Examples/GetParameterValues">
<p>Which of the programming languages you like the most</p>
<select name="lang">
<option value="C/C++">C/C++</option>
<option value="Java">C/C++</option>
<option value=".NET">C/C++</option>
<option value="Perl">C/C++</option>
<option value="Pascal">C/C++</option>
</select>
</form>
</body>
</html>


April 23, 2012 at 4:06 PM


Modify the servlet. It actually displays the selected values. So ti insert the selected values, try this:

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

public class GetParameterValues extends HttpServlet{
  protected void doPost(HttpServletRequest request, 
   HttpServletResponse response)
 throws ServletException, IOException {
String languages=" ";
  response.setContentType("text/html");
  PrintWriter pw = response.getWriter();
  String[] lang = request.getParameterValues("lang");
  for(int i=0; i<lang.length; i++){
  lanuages+=lang[i]+" ";
  }
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();

             st.executeUpdate("insert into data(languages) values('"+languages+"')");
            pw.println("Inserted Successfully!");
        }
catch(Exception e){}
  }
}


April 23, 2012 at 4:14 PM


import java.sql.* to the above servlet code.



Related Tutorials/Questions & Answers:
Mysql Multiple Date Insert
Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert... illustrate an example from 'Mysql Multiple Column Insert'. To understand an example
Mysql Multiple Date Insert
Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert... illustrate an example from 'Mysql Multiple Column Insert'.To understand
Advertisements
multiple language selection
multiple language selection  Hi how can i do a java program using swing that changes the language like malayalam/tamil etc with languages on a drop down menu
single selection of chechbox among multiple selection when in a loop.
single selection of chechbox among multiple selection when in a loop.  i am using cmd prompt to run and execute the java pgm. here i need your help... but here am getting multiple selection(previous selected item also coming again
Facing Problem to insert Multiple Array values in database - JSP-Servlet
Facing Problem to insert Multiple Array values in database  Hai... Quantity and Price . Pl help me to insert the multiple books details... --------------------------------------- i want to insert the data like the above
fetch and insert multiple rows into mysql database using jsp servlet
fetch and insert multiple rows into mysql database using jsp servlet  ... a problem to insert multiple rows into database using a single insert query...=con.createStatement(); String sql="insert into attendance(date,id,name,status
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
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
insert
insert  insert data in database from servlet through JDBC   Ho Friend, Please visit the following: Insert data into database Thanks
JTree Multiple Selection
_TREE_SELECTION and if you will allow the permission for multiple selection...: Multiple selection of visible nodes... Enable and Disable Multiple Selections in a JTree Component
interrelated two selection box
interrelated two selection box  hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database
highlight uitableviewcell on selection
the UITableViewCell on selection in my application.   UITableViewCell... highlight it or use the default selection for the cell in UITableView. Also you can disable the the stye by setting StyleNone to cell selection. But in case
Selection Using JoptionPane
Selection Using JoptionPane  Help, can someone provide me the code using JOptionPane for the following:- Part A 1) Prompt user to make 3 selection... Modify the above application so that if user makes a selection that the user has
checkbox selection in jsp
checkbox selection in jsp  hey guys i am working on a web based project using jsp. In my project i am having 9 check boxes in 3 rows in the same form. I want to select i check box from each row and also i want to avoid many
changing selection color of <button>
changing selection color of   dear all, i have loaded image in border less button tag when button is selected with tab key i get brown color rectangle around image. how do i change color of that rectangle from brown to white
selection box linked with textarea
selection box linked with textarea    function get_val(tot_val1) { document.getElementById('TextBox1').value = tot_val1; alert(tot_val1... detals i have in db with all fields .. like wise i have names in selection box sham
How to create textbox on combo value selection using javacsript in jsp?
How to create textbox on combo value selection using javacsript in jsp?  dynamically create textbox on combo value selection. when select multiple values then create multiple textboxes
enable text box and label on selection
enable text box and label on selection  hello, Please tell me how to enable label and text box on selection of drop down list box. in drop down list box all values come from database. please reply
Modifying a single row of database based on selection in jsp
Modifying a single row of database based on selection in jsp  Hi guys, i have a problem, I am Fetching the results from database and displaying...-Servlet/6051-update-multiple-rows-in-jsp.html
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
The INSERT INTO Statements in SQL?
The INSERT INTO Statements in SQL?  The INSERT INTO Statements in SQL?   Hi, The INSERT INTO statement is used to insert a new row or multiple rows into a table. SQL INSERT INTO Syntax INSERT INTO table_name VALUES
Image Selection Reply Urgent.. - JSP-Servlet
Image Selection Reply Urgent..  Respected Sir/Madam, I am R.Ragavendran.. Thanks for yuor fast response.. Sir actually I will be much more convenient if you provide me with coding.. I dont know to work with images as i
query regarding multiple select
query regarding multiple select  i have a select in jsp with multiple options.When i select multiple values i am not able to insert it into database and how do i retrieve them..please help me with an example code
Selection based on other selection in jsp
Selection based on other selection in jsp  I am trying to create... category there are products which are taken from a ms access table using a java... selection on same jsp page such that when someone select a category only the products
Syntax for image selection Urgent - JSP-Servlet
Syntax for image selection Urgent  Respected Sir/Madam, I am using the following syntax to know whether radio button has been clicked or not: for(var i=0;i  Hi friend, now show the question no 2129 Here
multiple inheritance
multiple inheritance  Class A extends Class B but Class A also inherit Super Class Object so it is multiple inheritence give reason in support of your answer
DB Insert
DB Insert  How to insert XML data into a database column? Column data type is CLOB
inserting multiple file formats into database
inserting multiple file formats into database  hi i want to insert multiple file format like .pdf.doc.zip into mysql database using jsp
Importance of Recruitment and Selection
the Recruitment and Selection is the basic significant factors which decides by Human Resource Department of the organization. Recruitment and Selection are one... be choose. On the other hand, Selection is the process where qualifications
Drop-down text selection in jsp/html
Drop-down text selection in jsp/html  Hi, I am trying to create JSP page where I have two drop-downs. There are two-sets of data - First set Categories- Movies, Books, Music and the Second set Genres- Action,Comedy,Romantic
 

 

 

DMCA.com