insert multiple selection - Java

Ads
 

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.

Ads









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
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
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
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
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
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
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
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
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
DB Insert
DB Insert  How to insert XML data into a database column? Column data type is CLOB
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
Mysql Insert
Mysql Insert       Mysql Insert is used to insert the records or rows to the table. Understand with Example The Tutorial illustrate an example from 'Mysql Insert'.To grasp
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
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
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
Add multiple UIBarButtonItem
Add multiple UIBarButtonItem  add multiple uibarbuttonitem
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
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 code jsp to access
insert code jsp to access   insert code jsp to access
The INSERT INTO Statement, SQL Tutorial
The INSERT INTO Statement       The INSERT INTO statement is used to insert or add a record of data into the table. To insert records into a table, just write the key word
mail with multiple attachments
mail with multiple attachments  code for sending mail with multiple attachments in jsp

Ads