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



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

Have Programming Question? Ask it here!
 
 
 


nishi
inserting data from radio buttons to database
2 Answer(s)      5 years 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
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
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
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
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
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
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
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 
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
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 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 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
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
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
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
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     
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
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
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
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 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
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
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
Database Scrolling Buttons
Database Scrolling Buttons  Sir, I have two button "Next" and "Previous". I'am able to retrieve data from database but I don't understand as to how display data on next and previous button clicks. Please help me out
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql database using php.... below my code is that.. <html> <head>
Getting Textbox data from database
data from database and display it on the textboxes. <%@page language="java...Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown
Inserting id in place of name to database
Inserting id in place of name to database  Hello, I have a database department where I have "id" and "name". I am fetching this data to a jsp form in dropdown list displaying "name" there and Now I wanted to insert data from
Getting Textbox data from database
;Here is a jsp code that retrieves data from database and display...Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown
Advertisements
 

 

 

DMCA.com