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



Home Answers Viewqa JSP-Servlet inserting dropdown values into database table
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


aswinks
inserting dropdown values into database table
4 Answer(s)      2 years and 8 months ago
Posted in : JSP-Servlet


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


Advertisement
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){}
              %>


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 values in MySQL database table
Inserting values in MySQL database table   ... the facility for inserting the values in MySQL database table. Description... insert values in the MySQL database table. We know that tables store data in rows
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
Inserting Image in Database Table
Inserting Image in Database Table   ... to the MySQL database table.  Flow of the process : This program helps the user to insert an image in the MySQL database table. To insert
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
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
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
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
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
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
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 Data In Database table using Statement
Inserting Data In Database table using Statement... a values into the table so we need to write a query for inserting the values... to insert the data in the database from our java program in the table stored
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
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
Inserting Image into table
Inserting Image into table  In this section , we will insert a image into a table. For inserting image, table's field (in which image will be stored) must be define as "blob". First, Create table'inImage'
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
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
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
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 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
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
inserting an path of an image in database - JDBC
inserting an path of an image in database  hello kindly help related... time its full path should be inserted in the database(MS Sql 2000).. I m able... be saved in the database...I have tried it but getting an error.. plz have a look
disallow NULL values in a table.
disallow NULL values in a table.  How do I disallow NULL values in a table
Inserting data on a database in servlet - JSP-Servlet
to a databse by a servlet.I used the example in "Inserting Data In Database table...Inserting data on a database in servlet  Hi I am following... of a table,that is none of the data which i tried to enter into database by using
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
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
 

 

 

DMCA.com