inserting data from radio buttons to database

Ads

 
 

Share on Google+Share on Google+

nishi
inserting data from radio buttons to database
2 Answer(s)      8 years ago
Posted in : JSP-Servlet
Ads
View Answers

September 16, 2009 at 2:40 PM


Hi Friend,

Try the following code:

1)radioButton.jsp:

<[email protected] 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:

<[email protected] 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


Ads









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
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
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
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
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 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
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 - 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
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
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
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
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
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
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
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
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
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
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
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
delete data from database - SQL
delete data from database  HOw to delete specific data from table> I want to delete one record from database. Thnx  Hi friend, -------------------------------------------- Visit for more information
To retrive data from database - Struts
To retrive data from database  How to get values ,when i select a select box in jsp and has to get values in textbox automatically from database? eg... come to jsp page automatically from database
Problem in accessing data from Database
Problem in accessing data from Database  hi..... i'm making a project on servlet and jsp with ms access 2007 at the backend. One field in my database is text and all others are of currency data type. If i enter 0 or null value
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
retrieve data from database with hyperlink
retrieve data from database with hyperlink  sir....i have one table called 'name' having two values i have to retrieve those data with a hyperlink and show in browser and if we click hyperlink its shows his sub categories....how