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 want Select any One JRadioButton At a Time out of Two.
plz Give Me Code Sir.
View Answers
March 8, 2010 at 12:50 PM
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("Name");
final JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Age");
final JTextField jt2=new JTextField(15);
JLabel lbl3 = new JLabel("Gender");
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);
lbl3.setBounds(50,130,70,30);
button.setBounds(50,170,100,30);
jt1.setBounds(110,50,100,30);
jt2.setBounds(110,90,100,30);
Male.setBounds(110,130,100,30);
Female.setBounds(210,130,100,30);
text.setBounds(110,170,100,30);
text.setVisible(false);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String name=jt1.getText();
String age=jt2.getText();
int ag=Integer.parseInt(age);
String g=text.getText();
if((Male.isSelected()==false)&&(Female.isSelected()==false)){
JOptionPane.showMessageDialog(null,"Please select radio button");
}
else{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement st=con.prepareStatement("insert into names(name,age,gender) values(?,?,?)");
st.setString(1,name);
st.setInt(2,ag);
st.setString(3,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(lbl3);
f.add(jt1);
f.add(jt2);
f.add(Male);
f.add(Female);
f.add(button);
f.add(text);
f.setSize(1000,1000);
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
July 18, 2013 at 5:40 PM
i m not getting the output when i click on the submit buuton what to do
Related Tutorials/Questions & Answers:
Save JRadioButton Text in to database - Java BeginnersSave JRadioButton Text in to
database Hello Sir I have Two JaradioButtons
1)Semwise Course
2)Yearwise Course
I want To
Save Text
from...();
JOptionPane.showMessageDialog(null,"
Data is successfully inserted into
database.");
}
catch
Advertisements
how to access the MS ACCESS database with java how to
access the
MS ACCESS database with java
how to
access the
MS ACCESS database with java
how can we insert,delete,update,search records of
ms access with java
Java
MS Access database connectivity
Follow
how to connect to MS access database in JSP?how to connect to
MS access database in JSP?
how to connect to
MS access database in JSP? Any seetings/drivers need to be set or installed before...();
ResultSet rs=st.executeQuery("select *
from data");
while(rs.next()){
%>
<
How to access the database from JSP?How to
access the
database from JSP? Hi,
What is the process of accessing the
database from JSP page?
Thanks
Hi,
In the JSP program...
database from JSP which explains you
how to
access the
database by embedding
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
How to access (MySQL)database from J2ME?How to
access (MySQL)
database from J2ME? I am new to J2ME. I am using NetBeans.
Can anyone help me?
How to
access (MySQL)
database from J2ME?
( I search a lot I found that there is need to
access database through servlet
How to access data yearly from DB in C# ?How to
access data yearly
from DB in C# ?
how to
access data yearly
from database in C#.
I have code but i m not able to retrieve
data yearly
from... as Student_ID,payment
FROM fee" + ses + " where date1='" + date1
How to use JTable with MS-Access.
Here is an example that retrieves the
data from MS Access database...
How to use JTable with
MS-Access I have Three Column in
Database... = DriverManager.getConnection("jdbc:odbc:
access");
String sql = "Select *
from data";
Statement
How to use JTable with MS-Access.
Here is an example that retrieves the
data from MS Access database...
How to use JTable with
MS-Access I have Three Column in
Database... = DriverManager.getConnection("jdbc:odbc:
access");
String sql = "Select *
from data";
Statement
Migrating from mysql to MS AccessMigrating
from mysql to
MS Access Hi
I am hoping for some help
I need to write a conversion program (SQL statements) to import existing
data in a MYSQL
database to a
MS Access database.
any suggestions would be appreciated
retreiving data from microsoft access databaseretreiving
data from microsoft
access database
How can i retrieve
data from microsoft
access when i have select the vaules in combo box and text box. When i select these values... i want to retrieve the corresponding columns