Save JRadioButton Text in to database

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 option from that two RadioButtons.
plz Help Me Sir.
View Answers

March 24, 2010 at 10:39 AM

Hi Friend,

Try the following 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("Course");
text=new JTextField(15);
final JRadioButton c1,c2;
ButtonGroup radioGroup=new ButtonGroup();
c1=new JRadioButton("Semwise Course");
radioGroup.add(c1);
c2=new JRadioButton("Yearwise Course");
radioGroup.add(c2);
JButton button=new JButton("Submit");
text=new JTextField(15);
c1.addActionListener(al);
c2.addActionListener(al);
lbl1.setBounds(50,50,70,30);
button.setBounds(50,80,100,30);
c1.setBounds(110,50,200,30);
c2.setBounds(310,50,200,30);
text.setBounds(110,80,100,30);
text.setVisible(false);

button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if((c1.isSelected()==false)&&(c2.isSelected()==false)){
JOptionPane.showMessageDialog(null,"Please select radio button");
}
else{
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(ctype) values(?)");
st.setString(1,g);
int i=st.executeUpdate();
JOptionPane.showMessageDialog(null,"Data is successfully inserted into database.");
}
catch(Exception ex){}
}
}
});

f.add(lbl1);
f.add(c1);
f.add(c2);
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());
}
};
}

Thanks









Related Tutorials/Questions & Answers:
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... java.awt.*; import java.awt.event.*; public class SwingFrame{ JTextField text
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... JRadioButton I want Store Information from JRadioButton to MS Access Database, and I want Select any One JRadioButton At a Time out of Two. plz Give Me Code Sir
Advertisements
Problem with JRadioButton and Access Database - Java Beginners
Problem with JRadioButton and Access Database  Hello sir ,Here I have write following code to save text on JradioButton but this is not saved in Access Databse, I want to store course type in to database and also other fields
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...; Hi Friend, To insert JRadioButton text, you need to create a textfield
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
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 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 save database data into excelsheet using hibernate
How to save database data into excelsheet using hibernate  How to save database data into excelsheet using hibernate
uploading a text file into a database
uploading a text file into a database  how to upload a text file into a database using jchooser   import java.io.*; import java.sql....: "); final JTextField text=new JTextField(20); JButton b1=new JButton
SQL database parameters should save at where?
SQL database parameters should save at where?  Hi, Currently... the script will be running for very long time, I like to move the SQL database..., if there is a database changed (hostname, username or password) It should
how to import excel sheet into mysql database and save it as a table in database
how to import excel sheet into mysql database and save it as a table in database  sir, i want to import an excel sheet into a MySQL database and after importing it i want to store the excel sheet as a table in database
how to save uploaded image in database using javascript
how to save uploaded image in database using javascript  Please can you tell me how to store uploaded image in database using java I'll use...; Now i want to store it on database...ADS_TO_REPLACE_1 Please help me Thanks
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database.... Apache Tomcat/6.0.29  We have used MySQl database. 1)page.jsp: <
code save word file in 10g database - SQL
code save word file in 10g database  I am not having any idea to save the whole word document in Oracle 10g. Please help me.   Hi Friend, Try the following code: import java.io.*; import java.sql.*; public
save switch data into database - Java Beginners
save switch data into database  switch(menu) { case 1://add a student System.out.print("Enter student ID: "); int ID = scan.nextInt(); System.out.print("Enter your name: "); String name = scan.next(); break
what is proper way to save pictures in SQl database and call it through JSP ?
what is proper way to save pictures in SQl database and call it through JSP... 'getContextPath()' mehtod using this method I can call pictures and Text on same... type i can't see text on same page. Please tell me proper way to do
save multiple records into database using jsp/servlet mvc
save multiple records into database using jsp/servlet mvc  hai, this is my jsp where i have enter multiple username and password and save it to database in single hit user.jsp <form action="UserServlet" method="post
Save profile and image to mysql database, and view the image in another jsp page
Save profile and image to mysql database, and view the image in another jsp page  Pls. need help in saving the profile info with the image in mysql database.. some basic code pls in jsp... thanks in advance
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
How save,get picture from database in my jsp page?
How save,get picture from database in my jsp page?  How i save picture in db after browsing it,and also how i get it on my other jsp page
i want to save image on server folder. and i want to save URL of this folder and name of image in database
i want to save image on server folder. and i want to save URL of this folder and name of image in database  hi i want to save image on server folder. and i want to save URL of this folder and name of image in database.on click
How i upload file and save that record in database using JSP?
How i upload file and save that record in database using JSP?  Hi All, I m the beginner in JSP and I want to upload the file and store that file and some other form data in MySQL database. Ex. There is one employee detail form
Question about "Insert text file data into Database"
Question about "Insert text file data into Database"  Hey I was reading the tutorial "Insert text file data into Database", (awesome btw), and noticed that both a FileInputStream, a DataInputStream and a BufferedReader
How to save excel sheet into mysql database using blob or clob
How to save excel sheet into mysql database using blob or clob  Hi All, I am new to java and i need to upload excel sheet to mysql, please suggest me the steps to do this, i am able to connect to the database, from there i don't
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my code.. In jsp ... <form name=frm method="post" action="Device"> <table> <tr><TD ><B>Upload Image</B><
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my code.. In jsp ... <form name=frm method="post" action="Device"> <table> <tr><TD ><B>Upload Image</B><
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 the following code: import java.sql.*; import javax.swing.*; import
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table as if i am... type=\"text\" name=\"LASTNAME\" value=\"rs.getString(2)"></td>
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table wth edit...;"); out.println("<td><input type=\"text\" name=\"LASTNAME\" value
Java save file to database
Java save file to database In this section, you will learn how to insert file to database. Description of code: Firstly, we need to establish a connection between MySql database and java file with the help of various types of APIs
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
retrive record from the text field and insert into to database
retrive record from the text field and insert into to database  the following code is inserting values in the my sql database but i want to insert the data into oracle database , i want what changes i have to make
how can i store text box values as it is in database table
how can i store text box values as it is in database table  CUSTOMER DESCRIPTION
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
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking... getting data into textarea from database table by clicking on the button
how to get the image of a selected JRadioButton to another panel?
how to get the image of a selected JRadioButton to another panel?  how to get the image of a selected JRadioButton to another panel
Insert text into database table using JSP & jQuery
Insert text into database table using JSP & jQuery In this tutorial , the text is inserted into database table using JSP & jQuery. In the below example, the first JSP page is use to display text box in which we type data
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
place data in text fields from database using jdbc
place data in text fields from database using jdbc  i want get the data from database and place the records in the respective textfields using jdbc and swing like eno,ename,loc from emp table
Insert text file data into Database
Insert text file data into Database In this section, you will learn how to insert the text file data into the database. For this purpose, we have created... is then inserted into the database. Here is the student.txt: 1 
form text box connection with mysql database feild - JDBC
form text box connection with mysql database feild  Respected Sir, What is the coding to connect a form text box field with mysql database table field will you explain me with simple example.. thanking you.. 
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
) and save the new position (values) also in database(MySql)?  Hi members, I... table)from Database, Now i am Dragging and dropping one HTML table row to another position.I want to save the position ( new position) in database(MySql).How
Fetched Record from database show into text field of html page
Fetched Record from database show into text field of html page  hi, i have a database with field merchant_code, merchant_name, city, region... front end of html file to my database like that 001 sajal Noida North 002
Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database
Database, Now i am Dragging and dropping one HTML table row to another position.I want to save the position ( new position) in database(MySql).How to do this?Please...Dragging and dropping HTML table row to another position(In Jsp) and save
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please... save to database from JButton.Please give me a tutorial and source code... into database visit to : http://www.roseindia.net/tutorialsearch/?t=file
Write records into text file from database
Write records into text file from database You have already learnt how to insert records from text file to database. But here we are going to retrieve records from database and store the data into the text file. For this purpose, we have
how to send and retrieve image along with text to and from database
with the text to the database if the user presses the button. thanks im hoping...how to send and retrieve image along with text to and from database  .... i want to take the random image along with the text and send it to another user
While retrieving text from database onto JSP, the alignment of line and paragraphs is not followed
While retrieving text from database onto JSP, the alignment of line and paragraphs is not followed  I have stored text database through textarea box. While trying to retrieve the same text from db, the text displayed onto
automatically move next page when data fetched from database is stored in text field
automatically move next page when data fetched from database is stored in text field  hi I have php page where i have two text fields . The data are stored in database wherein when the in the first text field the data is already
upload a file into database and progrm should support excel and text and csv file formats
upload a file into database and progrm should support excel and text and csv file formats  Hai all, I need a program to upload a file into database table... and the program should support .excel ,.txt ,.csv file formats. can

Ads