insert multiple selection - Java

insert multiple selection - Java

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

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... The Section of Tutorial illustrate an example from 'Mysql Multiple Column Insert
Mysql Multiple Date Insert
Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert... of Tutorial illustrate an example from 'Mysql Multiple Column Insert
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
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
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
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:ADS_TO_REPLACE_1 Insert data into database Thanks
JTree Multiple Selection
the CONTIGUOUS_TREE_SELECTION and if you will allow the permission for multiple...: Multiple selection of visible nodes... Enable and Disable Multiple Selections in a JTree Component
ModuleNotFoundError: No module named 'selection'
ModuleNotFoundError: No module named 'selection'  Hi, My Python... 'selection' How to remove the ModuleNotFoundError: No module named 'selection' error? Thanks   Hi, In your python environment you
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
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.ADS_TO_REPLACE_1 SQL INSERT INTO Syntax INSERT
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
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
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
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
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
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
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
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'  Hi, My... named 'causal-selection' How to remove the ModuleNotFoundError: No module named 'causal-selection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'model-selection'  Hi, My... named 'model-selection' How to remove the ModuleNotFoundError: No module named 'model-selection' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'model-selection'  Hi, My... named 'model-selection' How to remove the ModuleNotFoundError: No module named 'model-selection' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'blacken-selection'
ModuleNotFoundError: No module named 'blacken-selection'  Hi, My... named 'blacken-selection' How to remove the ModuleNotFoundError: No module named 'blacken-selection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'  Hi, My... named 'causal-selection' How to remove the ModuleNotFoundError: No module named 'causal-selection' error? Thanks   Hi, In your
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
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
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
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
Add multiple UIBarButtonItem
Add multiple UIBarButtonItem  add multiple uibarbuttonitem
Mysql Insert
Mysql Insert       Mysql Insert is used to insert the records or rows to the table. Understand with ExampleADS_TO_REPLACE_1 The Tutorial illustrate an example from 'Mysql Insert
multiple inhertence
multiple inhertence  package start; class A { protected void a() //a method in A { System.out.println("Class A"); } } class B extends A { public B() { super
multiple inhertence
multiple inhertence  package start; class A { protected void a() //a method in A { System.out.println("Class A"); } } class B extends A { public B() { super
insert data
insert data  i've got a problem to insert my data to database.i can upload my multipart file but not text data.Please help me to solve this .Attached...("insert into images values(?,?,?,?,?)"); st.setString(2
ModuleNotFoundError: No module named 'colcon-package-selection'
ModuleNotFoundError: No module named 'colcon-package-selection'  Hi...: No module named 'colcon-package-selection' How to remove the ModuleNotFoundError: No module named 'colcon-package-selection' error? Thanks  
ModuleNotFoundError: No module named 'ecg-feature-selection'
ModuleNotFoundError: No module named 'ecg-feature-selection'  Hi...: No module named 'ecg-feature-selection' How to remove the ModuleNotFoundError: No module named 'ecg-feature-selection' error? Thanks   Hi
ModuleNotFoundError: No module named 'naive-feature-selection'
ModuleNotFoundError: No module named 'naive-feature-selection'  Hi...: No module named 'naive-feature-selection' How to remove the ModuleNotFoundError: No module named 'naive-feature-selection' error? Thanks   
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection' ...: No module named 'odoo11-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox'
ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox'  ...: No module named 'rpi-feature-selection-toolbox' How to remove the ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox' error
ModuleNotFoundError: No module named 'branch-and-bound-feature-selection'
ModuleNotFoundError: No module named 'branch-and-bound-feature-selection' ...: ModuleNotFoundError: No module named 'branch-and-bound-feature-selection' How to remove the ModuleNotFoundError: No module named 'branch-and-bound-feature-selection
ModuleNotFoundError: No module named 'colcon-package-selection'
ModuleNotFoundError: No module named 'colcon-package-selection'  Hi...: No module named 'colcon-package-selection' How to remove the ModuleNotFoundError: No module named 'colcon-package-selection' error? Thanks  
ModuleNotFoundError: No module named 'ecg-feature-selection'
ModuleNotFoundError: No module named 'ecg-feature-selection'  Hi...: No module named 'ecg-feature-selection' How to remove the ModuleNotFoundError: No module named 'ecg-feature-selection' error? Thanks   Hi
ModuleNotFoundError: No module named 'feature-selection-fdr'
ModuleNotFoundError: No module named 'feature-selection-fdr'  Hi...: No module named 'feature-selection-fdr' How to remove the ModuleNotFoundError: No module named 'feature-selection-fdr' error? Thanks   Hi
ModuleNotFoundError: No module named 'knock-feature-selection'
ModuleNotFoundError: No module named 'knock-feature-selection'  Hi...: No module named 'knock-feature-selection' How to remove the ModuleNotFoundError: No module named 'knock-feature-selection' error? Thanks   
mail with multiple attachments
mail with multiple attachments  code for sending mail with multiple attachments in jsp

Ads