sushant
How to save Selected text of RadioButton in to Access Databse
1 Answer(s)      5 years and 3 months ago
Posted in : Java Beginners
Sir I wnt To store Selected JRadioButton Text in to access Database
plz Help Me Sir.
and how to link website in to our Java Application with JRadioButton.
Advertisement
View Answers

March 20, 2010 at 11:38 AM


Hi Friend,

To insert JRadioButton text, you need to create a textfield which should be invisible on the frame. This textfield will get the selected radio button value using ActionListener.

Here is the code:

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingFrame{
JTextField text;

public static void main(String[] args) throws Exception{
SwingFrame sf=new SwingFrame();
}
public SwingFrame(){
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Name");
final JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Gender");
text=new JTextField(15);
final JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
radioGroup.add(Male);
Female=new JRadioButton("Female");
radioGroup.add(Female);
JButton button=new JButton("Submit");
text=new JTextField(15);
Male.addActionListener(al);
Female.addActionListener(al);
lbl1.setBounds(50,50,70,30);
lbl2.setBounds(50,90,70,30);

button.setBounds(50,130,100,30);
jt1.setBounds(110,50,100,30);
Male.setBounds(110,90,100,30);
Female.setBounds(210,90,100,30);
text.setBounds(110,130,100,30);
text.setVisible(false);

button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String name=jt1.getText();
String g=text.getText();

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement st=con.prepareStatement("insert into names(name,gender) values(?,?)");
st.setString(1,name);
st.setString(2,g);
int i=st.executeUpdate();
JOptionPane.showMessageDialog(null,"Data is successfully inserted into database.");
}
catch(Exception ex){}
}
});

f.add(lbl1);
f.add(lbl2);

f.add(jt1);

f.add(Male);
f.add(Female);
f.add(button);
f.add(text);
f.setSize(500,500);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText(((JRadioButton) e.getSource()).getText());
}
};
}









Related Tutorials/Questions & Answers:
How to save Selected text of RadioButton in to Access Databse - Java Beginners
How to save Selected text of RadioButton in to Access Databse  Sir I wnt To store Selected JRadioButton Text in to access Database plz Help Me Sir. and how to link website in to our Java Application with JRadioButton. 
How to save JCombobox Selected Item in to Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database  How to save JCombobox Selected Item in to Access Database  Hi Friend, Try...:access","",""); Statement stmt=con.createStatement(); ResultSet rs
Advertisements
selected radiobutton to display different page
selected radiobutton to display different page  there are three radio button are there , in that selected button to display different page. when submit it, using struts2 framework . plz help me to how write code
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc  how to make a radio button selected when retrieving data from database using struts framework and spring jdbc
radiobutton
radiobutton  how to add radiobutton in combobox in java
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.  I am using postgresql-8.4.4-1-windows as database, jboss-4.0.5.GA as server and jdk-6-windows-i586 with IDE
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend...:access","",""); Statement stmt=con.createStatement(); ResultSet rs
textfield selected text
textfield selected text  How to select text in text field
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database - Java Beginners
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database  Hello Sir I want Store Corse Type that contains Two JRadioButton I want Store Information from JRadioButton to MS Access Database, and I
how to dynamically add text boxes with add and remove link based on drop down choices, if a particular choice is selected.
how to dynamically add text boxes with add and remove link based on drop down choices, if a particular choice is selected.  how to dynamically add text boxes with add and remove link based on drop down choices, if a particular
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL  <html> <head> <...("text/html;charset=UTF-8"); PrintWriter out = response.getWriter
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL  <html> <head> <...("text/html;charset=UTF-8"); PrintWriter out = response.getWriter
how to save an input to jsp page in a text file?ave an input given b
how to save an input to jsp page in a text file?ave an input given b  how to save the input given by the user in jsp page to a text file
Accessing MS ACCESS databse using a HTML webpage [created using Javascript]
Accessing MS ACCESS databse using a HTML webpage [created using Javascript]  HI team, This is Srinivas, and I have a query and i explained here... I have to save some datas in an MS ACCESS database file [*.mdb], after
How to save run time created text-file on a disk using jsp/servlet?
How to save run time created text-file on a disk using jsp/servlet?  I have a JSP page with save button.In that I created the file(e.g a.txt) at run-time,when I click on the save button,it will ask where to save the file
how to connect two databse through HibernateFramework
how to connect two databse through HibernateFramework  how to connect two databse through HibernateFramework
Retrive data from databse to a text field - Java Server Faces Questions
Retrive data from databse to a text field  Hi, Can you give me a source code to rertrve data from Mysql databse to a text field using JSF.....by selecting option from a dropdown option
save text file - Java Beginners
save text file  hi i have just start programming in java.please guide me if i want to read a text file in java.then the text file is save in which directory
Save JRadioButton Text in to database - Java Beginners
Save JRadioButton Text in to database   Hello Sir I have Two JaradioButtons 1)Semwise Course 2)Yearwise Course I want To Save Text from JRadioBuuton in to Access Databse and Access Databse. with user can select any one
Javascript get Date And Selected Option Text
to get the selected option text and displayed in Javascript. This tutorial explains you that how to display the date and the selected option text in Javascript...Javascript get Date And Selected Option Text In this tutorial we will learn
RadioButton in Flex4
RadioButton in Flex4: In Flex4 RadioButton is a spark component. You can use two or more RadioButton components with in a RadioButtonGroup and select only one RadioButton at one time and if one stands in selected mode then all
save output in multiple text files
save output in multiple text files  Hi..I'm getting problem to store the output of this php code into multiple text files. Can anyone sugeest. Here is my code: <?php for($i=1; $i<=100; $i++) { $html = file_get
how to insert data from netbeans into databse
how to insert data from netbeans into databse  how to insert data from netbeans into databse   Please visit the following link: http://www.roseindia.net/webservices/web-services-database.shtml
RadioButton Control in Flex
text="Select any of the following RIA"/> <mx:RadioButton...RadioButton Control in Flex: The RadioButton control in Flex is a set... member of this group can be selected at a time. We can not select more than one
Radiobutton in Xcode
Radiobutton in Xcode  I am new to Xcode .I want to implement Radiobutton in Xcode (using Objective C),and when i select any Radiobutton ,it should remain selected when i open my view next time. Is it possible anyway ? Any advise
How to Display values from databse into table
How to Display values from databse into table  I want to display values from database into table based on condition in query, how to display...;b>Authors Name</b></td> <td>: <input type="text" name
How to save value in JSP
How to save value in JSP  Employee Name Time-IN Time-OUT... 324 2012-12-12 save i want to save dis value jsp to action ...how can i get all value ..and store..how can its values goes
radiobutton - JDBC
radiobutton  hi how do you insert a radiobutton into a table. eg: how to select army and put it into a column in JDBC. army is a part of the the group army navy air force
How to Connect J ComboBox with Databse - Java Beginners
How to Connect J ComboBox with Databse  How to Connect J ComboBox with Databse  Hi Friend, Do you want to get JComboBox values from database?Please clarify this. Thanks
How to Access MS Access in jar.
How to Access MS Access in jar.  how do i access my Ms-Access file... to access it via Code or is their any alter-native?? Do i need any Driver to do this ... i m able to access a Ms-access via JDBC but cant find the file wen