JSP Radio Button MySQL insert

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 select lists. I have created a servlet to connect to MySQL database and process the form. I have no problem inserting the text fields into the tables however I wanted to ask you if there are tutorials or perhaps you can help with the code to store radio button data and checkbox data to MySQL table. For example in the backend table there is only one column for Gender, how do I insert male OR female as selected through the form? thanks and regards,
View Answers

April 16, 2010 at 12:22 PM

Hi Friend,

Try the following code:

1)form.jsp
<html>
<form method="post" action="insert.jsp">
<table>
<tr><td>Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Gender</td><td><input type="radio" value="Male" name="gen">M <input type="radio" value="Female" name="gen">F</td></tr>
<tr><td>Languages</td><td><input type="checkbox" name="lang" value="Hindi">Hindi<input type="checkbox" name="lang" value="English">English<input type="checkbox" name="lang" value="French">French<input type="checkbox" name="lang" value="German">German</td></tr>
<tr><td><input type="Submit" value="Submit"></td></tr>
</form>
</html>

2)insert.jsp
<%@page import="java.sql.*"%>
<%
String name=request.getParameter("name");
String gender=request.getParameter("gen");
String checkValues[]=request.getParameterValues("lang");

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
String value="";
for(int i=0;i<checkValues.length;i++){
value+=checkValues[i]+" ";
}
Statement stmt = con.createStatement();
int j=stmt.executeUpdate("insert into person1(name,gender,languages) values('"+name+"','"+gender+"','"+value+"')");

}
catch(Exception e){}
%>

Thanks









Related Tutorials/Questions & Answers:
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
Radio Button Problem in jsp.
Radio Button Problem in jsp.  I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a radio button... radio button values from jsp to action using javascript
Advertisements
radio button in jsp - JSP-Servlet
radio button in jsp  hye there.how do I create radio button in jsp?Could you please gimme an example of shopping cart in jsp which have I have using a Netbean not a tomcat.What is the code for view and update in jsp?Thanks
Radio button in JSP - JSP-Servlet
Radio button in JSP  Hi! In my page I have two radio buttons. If i select first radio button. one text field has to be displayed.... If i select second radio button. text field has to be disappeared. pls.... help me.. 
Radio button validation using jsp - JSP-Servlet
Radio button validation using jsp  I had one jsp Page and servlet. I did my validations in servlet for my jsp page which contains the radio... a value for radio Buttons) then it will return to same jsp page with the given
On selecting a radio button, it should open a jsp page.
On selecting a radio button, it should open a jsp page.  Hi, COuld you please tell me how to link a radio button selection to a jsp. My requirement is if I select a radio button then it should open a jsp page. thank you
get a radio button click value - JSP-Servlet
get a radio button click value  thanks sir for sending code ,but i...") in servlet that is used in another jsp so can i call getParameter("radio") i.e in the input tag name="radio" eventhough i m getting a null value please help me
insert , edit , and delete button in one jsp page
insert , edit , and delete button in one jsp page  hello I want to ask about the way of creating a jsp page contains insert , edit , and delete buttons and manipulate data in database directly. any help please or hints
Radio button with values from a String ArrayList in JSP?
Radio button with values from a String ArrayList in JSP?  Radio button values in JSP ArrayList<String> cs = CourseAssignments.getInstance... input. I want to display a radio button near each course, then user selects one
radio button
radio button  On selecting a radio button, it should open a aspx page
How to use radio button in jsp page
How to use radio button in jsp page       This is detailed java code how to use radio button in jsp code and display a message in another jsp page according
when radio button is selected corresponding jsp page should open
when radio button is selected corresponding jsp page should open  how to write code in HTML & jsp, when we click on radio buttons the corresponding jsp page should open..!   <html> <script> function
get a value when a radio button clicked - JSP-Servlet
get a value when a radio button clicked  sorry sir my actual probs is that 1st i m callig a jsp in that i m displaying a table where i used a radio button to access a value(also used u r code),then in this jsp i m having a forms
insert name city and upload image in database using mysql and jsp
insert name city and upload image in database using mysql and jsp   insert name city and upload image in database using mysql and jsp
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..."><label> <input name="radiobutton" type="radio" value
Uploading Excel sheet record in JSP to insert data in MySql
Uploading Excel sheet record in JSP to insert data in MySql  Need Help how to upload Excel (.xls) file and insert data in Mysql using JSP it wil be wonder for me if any help me
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..."><label> <input name="radiobutton" type="radio" value
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..."><label> <input name="radiobutton" type="radio" value
How to identify the radio button id and row id in a table in jsp?
How to identify the radio button id and row id in a table in jsp?   function generateid(no) {var table = document.getElementById(tableID); var rowCount = table.rows.length
get a value when a radio button clicked - JSP-Servlet
get a value when a radio button clicked  Here is my code sir please help me if any changes in the code please give me sir thanks in advance...; //System.out.println("******* id in jsp login Is ******" +id); f.submit
RADIO FROM JSP TO ACTION.
RADIO FROM JSP TO ACTION.  Hi frds, how to get the selected multiple radio button values from jsp to action
Image selection instead of radio button very urgent.. - JSP-Servlet
Image selection instead of radio button very urgent..  Respected Sir/Madam, I am R.Ragavendran.. Actually in the following using radio... of this radio button. There must be an arrow or icon for each Emp ID. The color
Query on radio button
Query on radio button  I am having a multiple row in jsp page.They are dynamically coming. For each row there is one radio button. I want to select... are displayed in the jsp page using bean tag. Please provide me some suggestion
insert name city image in database using mysql and jsp
insert name city image in database using mysql and jsp  how to insert name ,city and image in database in mysql and jsp   Here is an example in jsp that insert name, city and image to database. <%@ page import
validation of radio button
validation of radio button  There are 3 radio button as A,B,W. there are another radio as 1,2,3.if we select W in first radio button then should select 2nd one(1,2,3).if we select A or B not need select any one from 1,2,3
Struts 2 Radio Button
radio buttons and I am using Struts2 tag.I want first rado button to be selected by default.But when i select the second radio button and hit on search button i want to retain the selection of that second radio button on search list
radio button - Development process
radio button  hi, there is 2 radio button and five text box... but when i click on cr radio button and enter value in text box.it enter the msg but it again go to sr radio button   Hi friend, Plz give full
How to save form fields into the MySql Database without submit button in jsp?
How to save form fields into the MySql Database without submit button in jsp?  I want to store user inputs into the database using javasccript or ajax or jqury but without submit button. Form Contains three fields
Insert a row in 'Mysql' table using JSP Code
Insert a row in 'Mysql' table using JSP Code In this section, we will discuss about how to insert data in Mysql database using JSP code. Query... between your Tomcat server & Mysql database Table. Code to insert row in Mysql
fetch and insert multiple rows into mysql database using jsp servlet
fetch and insert multiple rows into mysql database using jsp servlet  ... jsp form and want inserting it into my mysql database table. but i am having a problem to insert multiple rows into database using a single insert query
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
java radio button and exception
java radio button and exception  Dear Sir/Madam, I have problem with my addBagelRadioButton and addCheeseRadioButton. There should be only 1 radio button can be selected, but somehow 2 can be selected the same time. Also, I
Radio button Validation
Radio button Validation  Hi.. How to validate radio button in java?if the radio button is not selected an error message should be given... Please...()==false)){ JOptionPane.showMessageDialog(null,"Please select radio button
iPhone Radio Button Example
iPhone Radio Button Example  Can you please suggest me how to create Radio button in my iPhone application. Actually, in my application i have two... click on that button it get selected and by default it should display unselected
Insert Blob(Image) in Mysql table using JSP
Insert Blob(Image) in Mysql table using JSP In this Section, we will insert blob data(image) in Mysql database table using JSP code. A Blob stores a binary...; String url="jdbc:mysql://192.168.10.13:3306/ankdb"; try
pass radio button values to next page
pass radio button values to next page  how to pass selected radio button values which coming from mysql database to next page using php. Please show me with examples
dependent radio button
of the Radio Button is to select only one option at a time. So you don't need...dependent radio button  Hi. I have 4 radio buttons say all,chocolate,cookie,icecream. If I select all the other 3 should not able to be selected
code for insert button
code for insert button    i want code for insert button(in image) . This is to be used for inserting the values in mysql databases   The given code uses Swing components to create a image button and allow the user
passing value of radio button
passing value of radio button  hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two radio button in the first jframe.i have to get the selected item appear on the 3rd frame after passing through the second
radio button - Development process
radio button  hello,i want to creat two radio button.out of which only one can be selected.and can show the contain of selected radio box   Hi friend, Code to solve the problem : My Page Radio 11
access into radio button
access into radio button  access the four fields of database called access,access file and stored in radio button.please help
insert code jsp to access
insert code jsp to access   insert code jsp to access
Mysql Insert
Mysql Insert       Mysql Insert is used to insert the records or rows to the table. Understand with ExampleADS_TO_REPLACE_1 The Tutorial illustrate an example from 'Mysql Insert
Using radio button in struts - Struts
Using radio button in struts  Hello to all , I have a big problem... options to choose : Serial number 12345 radio button - selection 1 radio button - selection 2 Serial number 6789 radio button - selection 1 radio button
insert images into a Mysql database
insert images into a Mysql database  How can I insert images into a Mysql database
to get radio button value - Struts
to get radio button value   hello friend, i have a problem regarding... two major problems:- 1.these radio button is not going to select also 2.i want to set the "value" attribute of radio button in the above code. Can u help
insert excel sheet into mysql as a table
insert excel sheet into mysql as a table  sir, i want to import an excel sheet into mysql5.0 database as in the table format using tomcat 6.0 by jsp
Radio Button in HTML
Radio Button in HTML is a type of input form that allows a user to select one button from a group of button. When a user clicks on a radio button, it becomes...; specifies the component type is radio button or not. If a programmer use type="radio
Struts 2 radio button value problem
Struts 2 radio button value problem  When I use s:radio tag in struts...('radioButtonName').value.(Note :- I'm getting proper value in java from jsp) It always gives first radio option's value as the value for any option selected. Ex
Dojo Radio Button
Dojo Radio Button         .... For creating radio button you need "dijit.form.CheckBox". The radio button do some action on press.  Try Online: Radio ButtonADS_TO_REPLACE_1

Ads