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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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



Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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 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
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
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
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
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 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
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
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
selecting data from database
selecting data from database  how to select data from database using Dao in struts   Hi, You have to load the data from database using hibernate and send the data in a Java file object to jsp page. Please read at http
retrive data from database
retrive data from database   hi.. i made a application form. it's have attribute s.no,name,roll no and i enter a few records. now i want to view all record not in database access sheet i want to view it at any another
retrive data from database?
retrive data from database?  hellow i have a database sheet name as db1. it's contain sixty(60) sn,name ,rollno(primary key),father's name etc... from db1 and enter value in text box according there name,rollno and save
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 
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
fetch data from database in javascript
fetch data from database in javascript   How to fetch data from database in JavaScript when it is a leap year
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
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
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
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
 

 

 

DMCA.com