Home Answers Viewqa JSP-Servlet inserting data from radio buttons to database

 
 


nishi
inserting data from radio buttons to database
2 Answer(s)      3 years and 8 months ago
Posted in : JSP-Servlet

View Answers

September 16, 2009 at 2:40 PM


Hi Friend,

Try the following code:

1)radioButton.jsp:

<%@page import="java.sql.*"%>
<html>
<form method="post" action="answers.jsp">
<table>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from question");
int i=0;
while(rs.next()){
%>
<tr><td><%=rs.getString(2)%></td>
<td><input type="hidden" name="quid" value="<%=rs.getString(1)%>"><td><input type="radio" value="Poor" name="radio<%=i%>"/>Poor</td><td><input type="radio" value="Average" name="radio<%=i%>"/>Average</td><td><input type="radio" value="Good" name="radio<%=i%>"/>Good</td></tr>
<% i++;
}
%>
<tr><td><input type="Submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)answers.jsp:

<%@page import="java.sql.*"%>
<%
String id[] =request.getParameterValues("quid");
if(id !=null) {
for(int i=0;i<id.length;i++) {
System.out.println(id[i]);
}
}
String option[]= new String[5];
for(int i=0;i<5;i++){
option[i]=request.getParameter("radio"+i);
System.out.println(option[i]);
}
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st=conn.createStatement();
for(int j=0;j<5;j++){
String optionValue=option[j];
String qid=id[j];
System.out.println("update question set phone='jhgfhg' where questionid=1");
st.executeUpdate("update question set options='"+optionValue+"' where questionid='"+qid+"'");
}

out.println("Inserted Successfully");
}
catch(Exception e){
out.println(e);
}
%>

Thanks

March 31, 2013 at 8:31 PM


but using the above code it only displays the last value. my 1st page is <% try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sim?"+"user=root&password=yes");

String n[]=new String[50];
            String a[]=new String[50];
            String id[]=new String[50];
                int c=0,i=0;
                String s=null;
                String s1=request.getParameter("c_id");
                Statement st1=(Statement)con.createStatement();
                out.println("<br>");
                out.println("class");

                out.println(s1);
                out.println("<br>");                                   
                PreparedStatement pstmt=con.prepareStatement(" SELECT * FROM student, student_class WHERE student.s_id = student_class.s_id AND c_id = ? ");
                 pstmt.setString(1,s1);
                  ResultSet rs2= pstmt.executeQuery();
                    while(rs2.next())
                     {
                           s=rs2.getString("s_id");
                           out.println("Name: ");
                           String s2=rs2.getString("fname");
                          String s3=rs2.getString("mname");  
                            String s4=rs2.getString("lname");

                            out.println(s);                                                                                                              
                            out.println(s2);
                            out.println(s3);
                            out.println(s4);

                            n[c]=s; 
                            out.println("<br>"); 

                  out.println("---------------------");
                c++;
            %>



            <form name="stu_class" method="post" action="stu_class1.jsp" >
                                 <table>
                                     <tr>
                                     <br><input type="hidden" name="c_id" value="<%=s1%>"/>
                             PROMOTED<INPUT type=radio name="radio<%=i%>" value="p" request>
                         NOT PROMOTED:<INPUT type=radio name="radio<%=i%>" value="f" checked="true">
                              <td style="padding-top:2%">
                            </form>
                             <input type="hidden" name="c" value="<%=c%>"/>
                              </table>
                              <% 
                                        i++;
                     }  
                  session.setAttribute("n",n);

              %>     

                             <TD align="right" style="padding-right:20%">
                             <INPUT type="submit" value="Update" name="submit" >


            <% }
           catch (SQLException e) 
          {
              throw new ServletException("Servlet Could not display records.", e);
          }




and my 2nd page is
try 
         {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sim?"+"user=root&password=yes");
            String s1=request.getParameter("c_id");
          String s=request.getParameter("s_id");
            String c=request.getParameter("c");
            String id[]=new String[50];
            int t=Integer.parseInt(c);
            out.println(c);
           out.println(s);
            out.println(s1);
         //  String values[] =(String [])request.getParameterValues("a");
           String val[]=(String [])session.getAttribute("n");
           //  out.println(values[0]);
             //  out.println(val[0]);
                            for(int j=0;j<t;j++)
                {
                    out.println("<br>");
                     out.println(val[j]);       
                 }
          for(int i=0;i<t;i++)
          {
              out.println("test"); 
           id[i]=request.getParameter("radio"+i);
          out.println(id[i]);
            }
                       }
        catch (SQLException e) 
          {
              throw new ServletException("Servlet Could not display records.", e);
          }
                    %>

the problem is it displays only the last value of radio button









Related Pages:
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, i am getting error in my code of feedback form. once i finished selecting all the radio buttons and when i click on delete button. it points to the answer.jsp. answer.jsp
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, my problem... of radio buttons. the feedback.jsp should look like same as follows: Please... as per his choice. when user completes all the selection of radio buttons and he
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has the option field as options. but it is option in the table,so i changed
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem. i have a system to input data from a jform to a mysql database. i have made... to the data base. i use netbeans 7.2 and mysql 5.5 here is my code /* * To change
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem. i have a system to input data from a jform to a mysql database. i have made... to the data base. i use netbeans 7.2 and mysql 5.5 here is my code /* * To change
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... for each data cloumn ..at the time of end of the query... PLz see my code and point my
Inserting Data into mysql - SQL
Inserting Data into mysql  My sincere apologize for this post. I... into the SQL category though under php. I need help with reading from a csv file (using php)and inserting the details in a mysql database. Lets take for instance
WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS - Struts
for check boxes and radio buttons and for submit buttons. i have a jsp page which... check boxe values and radio button values to be saved in Data Base. pls help me...WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS 
radio buttons
radio buttons  write a program to create an applet button which has a list of radio buttons with titles of various colours.set the background colour... has a list of radio buttons with titles of various colors and a button
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... to handle all the action events from the buttons. **/ class ActionHandler... and then the result at the end.I need to add simple database connectivity
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... to handle all the action events from the buttons. **/ class ActionHandler... and then the result at the end.I need to add simple database connectivity
Inserting data in Excel File - Java Beginners
Inserting data in Excel File  Dear Sir, How can we fill the excel with fetched data from the database like Oracle, DB2? Is it possible to create an excel with filled data? Kindly give me the solutions to questions
Tab sequence problem with Radio buttons - JSP-Servlet
Tab sequence problem with Radio buttons  Hi, I have membership type in application as 1 year(radio button) 2 year(radio button) 4 year(radio button) courier delivery courier(radio button) currently tab sequence going
need help for writting code in struts action class for check boxes and radio buttons - Struts
buttons and for submit buttons. i have a jsp page which contains check boxes,radio...need help for writting code in struts action class for check boxes and radio buttons  Hello frnds, i need help from u esteemed and talented
inserting data into datafields
inserting data into datafields  I was raised with a query.... there is a button, on click on it....... few fields regenerates and the details entered there should be inserted into Database Number of times we click that button
Radio Buttons in DB Very Urgent - JSP-Servlet
Radio Buttons in DB Very Urgent  Respected Sir/Madam, I am... in the database.Here I need Radio Buttons added dynamically for each Row. When I click... the code.. Here When I click "View Database" Button,a JSP Page containing
Selecting a radio button in jquery autocomplete from database value
Selecting a radio button in jquery autocomplete from database value  I can get the data from the database using PDO to my jquery.js file. How do I... radio button? Here is the pertinent code: $("#name").autocomplete
JSP Radio Button MySQL insert - JSP-Servlet
JSP Radio Button MySQL insert  Hi, I have an HTML form which has a couple of radio buttons for example (gender: male/female) and some check boxes... with the code to store radio button data and checkbox data to MySQL table. For example
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
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below here there are list of radio buttons here in jsp page when the values are matched from database. I want to pass the selected value in Struts Action FormBean
Buttons
Buttons  I have created a web page with radio button group with two radio buttons for accepting the home appliances categories,Kitchen appliances... radio button is selected.Which event listener do I need to implement for this task
Radio Buttons in HTML
The Tutorial illustrates an example from Radio Buttons in HTML.In this Tutorial, the code explain to create a Radio Buttons. The code enables a user to select one... Radio Buttons in HTML     
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following... to a databse by a servlet.I used the example in "Inserting Data In Database table... of a table,that is none of the data which i tried to enter into database by using
Radio Buttons
Java: Radio Buttons Radio buttons (javax.swing.JRadioButton.... The example below produced this image. A radio button group starts with all buttons... radio buttons, puts them in a grid layout on a panel, and puts a titled
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below here there are list of radio buttons here in jsp page when the values are matched from database. I want to pass the selected value in Struts Action FormBean
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below here there are list of radio buttons here in jsp page when the values are matched from database. I want to pass the selected value in Struts Action FormBean
inserting into mysql database with uid to be primary key and autoincrement
; Here is the code of inserting values from jsp form to database...inserting into mysql database with uid to be primary key and autoincrement  hello, i am new to jsp and facing problem in creating a database entry
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons  i have a database having columns id(int),path(text),width(int),height(int... of various rows from database in labels by clicking previous and next
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons  i have a database having columns id(int),path(text),width(int),height(int... of various rows from database in labels by clicking previous and next
iBatis-Inserting data into database
iBatis-Inserting data into database   ... is inserting a row into database. And for this we are using MySQL as a database... namespace="Contact"> <!--- Inserting data in table --> <
Problem in inserting clob data in jsp
Problem in inserting clob data in jsp  how to insert any rich text editor data (which have more than 32766 characters) in a clob type column of oracle database with jsp
GWT -- retrive the data from Database
GWT -- retrive the data from Database  the user can create an event. In the create page, we have three buttons. Save as draft, preview and save and post buttons. Once the user entered all the datas and if he clicks the Preview
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
Inserting Data In Database table using Statement
Inserting Data In Database table using Statement... to insert the data in the database from our java program in the table stored... of the PrintWriter class. We can insert the data in the database only and only
Radio Buttons - Java Beginners
Radio Buttons  Hello Sir, How to create the code for the password... the radion buttons in display the same page in jsp.I need only how to make the question and answer page using the radio buttons.please help me to solve
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am... information from database the i want to show cash radio button checked.How can i do... database and according to that i want to check the cash cheque radio button
Inserting data from the HTML page to the database
Inserting data from the HTML page to the database... program in which we are going to insert the values in the database table from... of the PrintWriter class. We can insert the data in the database only and only
retreive integer data from database
retreive integer data from database  i made a table named result... and two buttons "ok" and "cancel" i want to take input from textfield...=lalit&database=mydb"); String url="select marks from student where rollno
Display Label and radio buttons runtime with respect to DB values
Display Label and radio buttons runtime with respect to DB values  Requirement: I am getting alertCondition,Y,W values from DB the the cooresponding... from buttongroup-Y JradioButton from buttongroup-N and i have multiple values
hibernate firstExample not inserting data - Hibernate
problem is data is not inserting into DB even though the program is executed... DEFAULT CHARSET=latin1 data is not inserting... in it by reading them from form object System.out.println("Inserting Record
Radio Button Problem in jsp.
for each row as i got data from the database using iterator tag,but when i... radio button values from jsp to action using javascript...Radio Button Problem in jsp.  I have a small doubt in my application
radio nuttpn
radio nuttpn  i have created a html page containing 20 multiple choice questions when i clicl the options which are radio buttons. I have tp retroebe it in a jsp pahe ansabe it in mysql database...further i have to match
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
pbml in inserting selected item from combobox into mysql - XML
pbml in inserting selected item from combobox into mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide... successfully.alert box have to display only if data was stored in database otherwise it has
Radio Buttons in Jsp - JSP-Servlet
Radio Buttons in Jsp  Hi, i have a page in which there are lot of radio buttons [IMG]http://i38.tinypic.com/jzi6vc.jpg[/IMG] see the above picture..." depending on the value in the String radio button has to be checked. How to do
inserting image in mysql database using browse button in servlets
inserting image in mysql database using browse button in servlets  Hi,I want to insert a image in mysql database using browse button. and, i want to display all inserted images in a form from there i want to download the image
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
Buttons
Java: Buttons There are many kinds of buttons, all derived from the AbstractButton class. ComponentsDescription JButton This is a standard button..., ButtonGroup Radio buttons are a group of buttons that can have at most one
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.