inserting dropdown values into database table

Ads
 

inserting dropdown values into database table

hi i want to insert dropdown values into a database table by using jsp.

View Answers

April 23, 2012 at 4:07 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

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:08 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" multiple>
<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

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:12 PM

1)form.jsp:

<html>
<body>
<form method = "post" action = "insert.jsp">
<p>Which of the programming languages you like the most</p>
<select name="lang" multiple>
<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)insert.jsp

<%@page import="java.io.*"%>

<%@page import="java.sql.*"%> <% String languages=" "; String[] lang = request.getParameterValues("lang"); for(int i=0; i


April 23, 2012 at 4:13 PM

1)form.jsp:

<html>
<body>
<form method = "post" action = "insert.jsp">
<p>Which of the programming languages you like the most</p>
<select name="lang" multiple>
<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)insert.jsp

  <%@page import="java.io.*"%>
     <%@page import="java.sql.*"%>
            <%
              String languages=" ";
              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+"')");
            out.println("Inserted Successfully!");
                    }
            catch(Exception e){}
              %>

Ads









Related Tutorials/Questions & Answers:
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  ... to insert all selected values in data base correspondent to each like if user selected india and then goa. I want to insert it to a table which has two fields
Advertisements
inserting all the values in a html table column
inserting all the values in a html table column  strong text hai everyone, i'm a fresher to servlet i need to know that, how can i insert all the values in a html table column into a database. Thanks in advance
store dropdown box values in database server
store dropdown box values in database server  how to store dropdown box values in database server in jsp
getting error while inserting values in database
getting error while inserting values in database  AddUser.java... into LTCINFO.PERSONS values ('"+LASTNAME+"','"+FIRSTNAME+"','"+ADDRESS+"','"+CITY...) { out.println("An Error Had occurred while accessing the database
fetch values in dropdown
fetch values in dropdown  in my application i want fetch dropdown values in jsp page through servlet. means i have to fetch the database fields values in array variable of servlet and then i have to print those values in dropdown
Inserting id in place of name to database
Inserting id in place of name to database  Hello, I have a database... in dropdown list displaying "name" there and Now I wanted to insert data from this form to another table and in place of "name" of department I wanted to insert
how to display values from database into table using jsp
how to display values from database into table using jsp  I want to display values from database into table based on condition in query, how... the values from database based on the bookname or authorname entered must be display
Query to insert values in the empty fields in the last row of a table in Mysql database?
Query to insert values in the empty fields in the last row of a table in Mysql database?  I have some fields filled and some fields empty in the last row of my MYSQL database. Now I want to fill up those empty fields in the last
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
how can i store text box values as it is in database table
how can i store text box values as it is in database table  CUSTOMER DESCRIPTION
Inserting a value to an Enum field in Table
Inserting a value to an Enum field in Table  I'm writing a code that creates a user account and sends the result to the user table in a mysql database. For example, in the user table I have: username varchar(15) PRIMARY KEY
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from the database) My question is when i select a particular value it should be pass
ajax+dropdown+table format
ajax+dropdown+table format  HI, i am looking for an ajax application which must contain two dropdown list.In first dropdown if i select a manager name from the first dropdown all the reporties under the selected manager should
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
) and save the new position (values) also in database(MySql)?  Hi members, I have one Html table in jsp page and i am iterating values (in columns of html table)from Database, Now i am Dragging and dropping one HTML table row to another
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
Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database
table in jsp page and i am iterating values (in columns of html table)from Database, Now i am Dragging and dropping one HTML table row to another position.I...Dragging and dropping HTML table row to another position(In Jsp) and save
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
problem on jsp, inserting data into table(mysql).
problem on jsp, inserting data into table(mysql).  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table name also is given by the user.My database
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration...,uniqueid,userfield,cdrcost) values ('" + calldate + "','" + clid + "','" + src
How to display all the Select values from the MySQL database table in where condition= In JSP?
How to display all the Select values from the MySQL database table in where... to display all the select values from MySQL DB** only first value is displayed in the jsp file. @select * from table dept where dept_no=10;" jsp code i have used
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... and then the result at the end.I need to add simple database connectivity to it just a single table i guess which would have sno,username result and percentage
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... and then the result at the end.I need to add simple database connectivity to it just a single table i guess which would have sno,username result and percentage
jsp- database dependent dropdown list
jsp- database dependent dropdown list   i want 2 dropdown list 1- CLASS 2-SECTION both are should come from database. and if i select a class suppose class a the corresponding section dropdown list should retrieve the section
inserting into mysql database with uid to be primary key and autoincrement
; Here is the code of inserting values from jsp form to database. In the database table, set the uid as the primary key and auto-increment. Then, whenever...inserting into mysql database with uid to be primary key and autoincrement 
Lock while inserting/updating database in multithreaded.
Lock while inserting/updating database in multithreaded.  Hi, I am having a multithreaded process which replicates the data from many table to one... inserting/updating to database. I dont know what is the issue but it was never
Dropdown code to retrieve result from oracle database
that will retrieve values from the database into dropdown. As the user choose any option from the dropdown, corresponding values will get displayed in the textboxes...Dropdown code to retrieve result from oracle database  Hi Friends, I
inserting multiple file formats into database using html
inserting multiple file formats into database using html   hi the code was working fine,i want to choose the file and then upload to database,by using html.whether it is possible to upload larger file size,please explain
jsp -sevlet connecting to database using dropdown
jsp -sevlet connecting to database using dropdown  How can I get my dropdown list from oracle database and then submit it to another table in JSP. I... to the database and fetches an array of strings from a database table and then sends
getting and storing dropdown list in database in jsp
getting and storing dropdown list in database in jsp  i have a drop down list to select book from database. i'm able to retrieve dropdown list from database. but unable to store the selected value in database table. please help
3 dropdown list from the database using JSP
3 dropdown list from the database using JSP  Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP

Ads