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 value .
plz help Me.
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
class coursefrm {
JFrame f;
JPanel p1,p2,p3;
JTabbedPane tp;
ImageIcon btnimg1,btnimg2;
JLabel l1, l2, l3, l4,l5,l6,l7,l8,l9,l10,l11,l12;
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;
JRadioButton r1,r2;
JScrollPane sp1;
JTextField text;
JButton savebtn,resetbtn,editbtn1,editbtn2,deletebtn ;
coursefrm(){
f=new JFrame("Form");
p1=new JPanel(new GridLayout(7,3));
p2=new JPanel(new GridLayout(6,2));
p3=new JPanel(new GridLayout(2,2));
tp=new JTabbedPane();
l1=new JLabel("Course ID:");
l2=new JLabel("Course Name:");
l3=new JLabel("Duration:");
l4=new JLabel("Fees:");
l5=new JLabel("Enter Course ID:");
l7=new JLabel("Course ID:");
l8=new JLabel("Course Name:");
l9=new JLabel("Duration:");
l10=new JLabel("Fees:");
l11=new JLabel("Course Type:");
l12=new JLabel();
text=new JTextField(15);
tf1=new JTextField(12);
tf2=new JTextField(12);
tf3=new JTextField(12);
tf4=new JTextField(12);
tf5=new JTextField(12);
tf6=new JTextField(12);
tf7=new JTextField(12);
tf8=new JTextField(12);
tf9=new JTextField(12);
tf10=new JTextField(12);
r1=new JRadioButton("SemWise");
r2=new JRadioButton("YearWise");
savebtn=new JButton(" Add ");
resetbtn=new JButton(" Reset");
editbtn1=new JButton(" Edit ");
editbtn2=new JButton(" Save");
deletebtn=new JButton("Delete");
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(l3);
p1.add(tf3);
p1.add(l4);
p1.add(tf4);
p1.add(l11);
p1.add(r1);
p1.add(l12);
p1.add(r2);
p1.add(savebtn);
p1.add(resetbtn);
p2.add(l7);
p2.add(tf7);
p2.add(l8);
p2.add(tf8);
p2.add(l9);
p2.add(tf9);
p2.add(l10);
p2.add(tf10);
p2.add(editbtn1);
p2.add(editbtn2);
p3.add(l5);
p3.add(tf5);
p3.add(deletebtn);
resetbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
}
});
savebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
int value1=Integer.parseInt(tf1.getText());
String value2=tf2.getText();
int value3=Integer.parseInt(tf3.getText());
int value4=Integer.parseInt(tf4.getText());
String g=text.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:mydsn","","");
PreparedStatement st=con.prepareStatement("insert into course(id,name,duration,fees,coursetype) values(?,?,?,?,?)");
st.setInt(1,value1);
st.setString(2,value2);
st.setInt(3,value3);
st.setInt(4,value4);
st.setString(5,g);
st.executeUpdate();
JOptionPane.showMessageDialog(p1,"Data is successfully inserted into database.");
con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(p1,"Error in submitting data!");
}
}
});
deletebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=tf5.getText();
int ide=Integer.parseInt(value1);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:mydsn","","");
PreparedStatement st=con.prepareStatement("DELETE FROM course WHERE id = ?");
st.setInt(1,ide);
st.executeUpdate();
JOptionPane.showMessageDialog(p3,"Record is deleted successfully.");
con.close();
}
catch(Exception exp3){
JOptionPane.showMessageDialog(p3,"Error in deleting record.");
}
}
});
editbtn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value=tf7.getText();
int ide=Integer.parseInt(value);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:mydsn","","");
PreparedStatement st=con.prepareStatement("select * from course where id=?");
st.setInt(1,ide);
ResultSet res=st.executeQuery();
res.next();
tf7.setText(Integer.toString(res.getInt(1)));
tf8.setText(res.getString(2));
tf9.setText(res.getString(3));
tf10.setText(Integer.toString(res.getInt(4)));
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(p2,"Can not edit data");
}
}
});
editbtn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
try
{
int x=JOptionPane.showConfirmDialog(p2,"Confirm edit? All data will be replaced");
if(x==0){
try{
int value1=Integer.parseInt(tf7.getText());
String value2=tf8.getText();
int value3=Integer.parseInt(tf9.getText());
int value4=Integer.parseInt(tf10.getText());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:mydsn","","");
Statement st=con.createStatement();
//System.out.println("update course set name='"+value2+"', duration='"+value3+"',fees='"+value4+"' where id='"+value1+"'");
st.executeUpdate("update course set name='"+value2+"' , duration="+value3+",fees="+value4+" where id="+value1+"");
JOptionPane.showMessageDialog(p2,"Updated successfully");
con.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(p2,"Error in updating edit fields");
}
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(p2,"Error");
}
}
});
}
void dis()
{
f.getContentPane().add(tp);
tp.addTab("Add Record",p1);
tp.addTab("Edit Record",p2);
tp.addTab("Delete Record",p3);
f.setSize(350,180);
f.setVisible(true);
f.setResizable(true);
}
public static void main(String z[]){
coursefrm pro=new coursefrm();
pro.dis();
}
/*public ActionListener al ( new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText(((JRadioButton) e.getSource()).getText());
}
});*/
}
View Answers
March 27, 2010 at 10:30 AM
Hi Friend,
You haven't performed any action on radio button.We have modified your code.Now it works.
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
class coursefrm {
JFrame f;
JPanel p1,p2,p3;
JTabbedPane tp;
ImageIcon btnimg1,btnimg2;
JLabel l1, l2, l3, l4,l5,l6,l7,l8,l9,l10,l11,l12;
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;
JRadioButton r1,r2;
JScrollPane sp1;
JTextField text;
JButton savebtn,resetbtn,editbtn1,editbtn2,deletebtn ;
coursefrm(){
f=new JFrame("Form");
p1=new JPanel(new GridLayout(7,3));
p2=new JPanel(new GridLayout(6,2));
p3=new JPanel(new GridLayout(2,2));
tp=new JTabbedPane();
l1=new JLabel("Course ID:");
l2=new JLabel("Course Name:");
l3=new JLabel("Duration:");
l4=new JLabel("Fees:");
l5=new JLabel("Enter Course ID:");
l7=new JLabel("Course ID:");
l8=new JLabel("Course Name:");
l9=new JLabel("Duration:");
l10=new JLabel("Fees:");
l11=new JLabel("Course Type:");
//l12=new JLabel();
text=new JTextField(12);
tf1=new JTextField(12);
tf2=new JTextField(12);
tf3=new JTextField(12);
tf4=new JTextField(12);
tf5=new JTextField(12);
tf6=new JTextField(12);
tf7=new JTextField(12);
tf8=new JTextField(12);
tf9=new JTextField(12);
tf10=new JTextField(12);
r1=new JRadioButton("SemWise");
r2=new JRadioButton("YearWise");
savebtn=new JButton(" Add ");
resetbtn=new JButton(" Reset");
editbtn1=new JButton(" Edit ");
editbtn2=new JButton(" Save");
deletebtn=new JButton("Delete");
r1.addActionListener(al);
r2.addActionListener(al);
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(l3);
p1.add(tf3);
p1.add(l4);
p1.add(tf4);
p1.add(l11);
p1.add(r1);
p1.add(text);
p1.add(r2);
p1.add(savebtn);
p1.add(resetbtn);
p2.add(l7);
p2.add(tf7);
p2.add(l8);
p2.add(tf8);
p2.add(l9);
p2.add(tf9);
p2.add(l10);
p2.add(tf10);
p2.add(editbtn1);
p2.add(editbtn2);
p3.add(l5);
p3.add(tf5);
p3.add(deletebtn);
text.setVisible(false);
resetbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
}
});
savebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
int value1=Integer.parseInt(tf1.getText());
String value2=tf2.getText();
int value3=Integer.parseInt(tf3.getText());
int value4=Integer.parseInt(tf4.getText());
String g=text.getText();
System.out.println(g);
March 27, 2010 at 10:30 AM
continue..
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:access","","");
PreparedStatement st=con.prepareStatement("insert into course(id,name,duration,fees,coursetype) values(?,?,?,?,?)");
st.setInt(1,value1);
st.setString(2,value2);
st.setInt(3,value3);
st.setInt(4,value4);
st.setString(5,g);
st.executeUpdate();
JOptionPane.showMessageDialog(p1,"Data is successfully inserted into database.");
con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(p1,"Error in submitting data!");
}
}
});
deletebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=tf5.getText();
int ide=Integer.parseInt(value1);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:mydsn","","");
PreparedStatement st=con.prepareStatement("DELETE FROM course WHERE id = ?");
st.setInt(1,ide);
st.executeUpdate();
JOptionPane.showMessageDialog(p3,"Record is deleted successfully.");
con.close();
}
catch(Exception exp3){
JOptionPane.showMessageDialog(p3,"Error in deleting record.");
}
}
});
editbtn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value=tf7.getText();
int ide=Integer.parseInt(value);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:mydsn","","");
PreparedStatement st=con.prepareStatement("select * from course where id=?");
st.setInt(1,ide);
ResultSet res=st.executeQuery();
res.next();
tf7.setText(Integer.toString(res.getInt(1)));
tf8.setText(res.getString(2));
tf9.setText(res.getString(3));
tf10.setText(Integer.toString(res.getInt(4)));
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(p2,"Can not edit data");
}
}
});
editbtn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
try
{
int x=JOptionPane.showConfirmDialog(p2,"Confirm edit? All data will be replaced");
if(x==0){
try{
int value1=Integer.parseInt(tf7.getText());
String value2=tf8.getText();
int value3=Integer.parseInt(tf9.getText());
int value4=Integer.parseInt(tf10.getText());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:mydsn","","");
Statement st=con.createStatement();
//System.out.println("update course set name='"+value2+"', duration='"+value3+"',fees='"+value4+"' where id='"+value1+"'");
st.executeUpdate("update course set name='"+value2+"' , duration="+value3+",fees="+value4+" where id="+value1+"");
JOptionPane.showMessageDialog(p2,"Updated successfully");
con.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(p2,"Error in updating edit fields");
}
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(p2,"Error");
}
}
});
}
void dis()
{
f.getContentPane().add(tp);
tp.addTab("Add Record",p1);
tp.addTab("Edit Record",p2);
tp.addTab("Delete Record",p3);
f.setSize(350,180);
f.setVisible(true);
f.setResizable(true);
}
public static void main(String z[]){
coursefrm pro=new coursefrm();
pro.dis();
}
private ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText(((JRadioButton) e.getSource()).getText());
}
};
}
Thanks
Related Tutorials/Questions & Answers:
Advertisements
Save JRadioButton Text in to database - Java BeginnersSave
JRadioButton Text in to
database Hello Sir I have Two... JRadioBuuton in to
Access Databse
and
Access Databse. with user can select any one...=new JTextField(15);
final
JRadioButton c1,c2;
ButtonGroup radioGroup=new
ACCESS DATABASE FROM HTMLACCESS DATABASE FROM HTML I want to
access sql 2008
database in html page without help of ADODB connection.. because if
access through ADODB means there is a security
problem. so,
Access database in html page(client side
problem in database problem in
database thanks for web site.
I want change this code to insert data into PostgreSql
database using jsp,servlets.
but i getting...){
out.println("Couldn't load
database driver: " + e.getMessage());
}
catch
database problemdatabase problem I did connect my jsp page to
database and it showed the result on another jsp page but i want to show the data of that field on which i click to mouse from the jsp page where all the data field has been showed
database problemdatabase problem I did connect my jsp page to
database and it showed the result on another jsp page but i want to show the data of that field on which i click to mouse from the jsp page where all the data field has been showed
Connect database in Access to Netbean?Connect
database in
Access to Netbean? how to connect
database in micrsoft
access to Netbean?i know it can be connected by using JDBC-ODBC bridge, can i know the steps in connecting the
database?
Is there any source code
Access 2007 database connectivityAccess 2007
database connectivity i design an application form... source and destination. pls tell me the code of connectivity with
access 2007
database using JComboBox.thanks
connecting to access database
Add a user DSN
Select Microsoft
Access Driver(*.mdb)
Select
database name...connecting to
access database print("code sample");Hi I Write java... this there is no error but my data is not going to my Acess
Database.
There is working
problem in jsp using ms-accessproblem in jsp using ms-access after starting server(tomcat) wen v... and select the driver Microsoft
Access Driver(*.mdb).
3)After selecting... the driver Microsoft
Access Driver(*.mdb).
3)After selecting the driver, click
Problem in accessing data from DatabaseProblem 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... someone plz help me out with this
problem how to access database in applethow to
access database in applet HI...
I'm having an applet where we should display the
database values in the applet...
It works fine in the local system(same network)...
but when its in the server, we r getting null values
How to access the database from JSP?How to
access the
database from JSP? Hi,
What is the process... you can
access the
database by embedding the JDBC code. But this is not the best...
database from JSP which explains you how to
access the
database by embedding
Applet database access - AppletApplet
database access HI...
I'm having an applet where we should display the
database values in the applet...
It works fine in the local system...
but when its in the server, we r getting null values in the local system..
I
java servlet connectivity problem with accessjava servlet connectivity
problem with access Import java.sql
javax.servlet
//all packages entered
try {
Class.forName...=con.createStatement();
^
i am confused what is the
problem JSP and Database accessJSP and
Database access Hi,
Please help me with the following program. I am not able to update all the pa column values in my
database.
csea.jsp:
<html>
<body>
<%@page import="java.sql.*"%>
<form method
Oracle 9i database problemOracle 9i
database problem Hi Somebody has given the solution but i.............,send reply immediately. I have a
problem in Oracle9i .I have installed... what i created .But after closing the SQL+ ,the
problem started.When i again opened
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
MS-ACCESS Query Problem - SQLMS-
ACCESS Query Problem hi sir
i have table which is initially have empty records
Deleted
Attributes:
Roll
Name
Add
Age
Course
Class... = DriverManager.getConnection("jdbc:odbc:
access");
Statement st
Database problem - WebSevices simple
database connectivity code. if you have any
problem then send me detail...
Database problem Hello,
How i connect my
database file& tables to Zend library file. In which library file i should change that code
Database fetching problemDatabase fetching problem I have multiple
database table and want to get all records in one object how can i do this.Pls guide
database connectivity problemdatabase connectivity problem what if client dont have
database with them then what is other way to run successfully our programm
Please visit the following link:
http://www.roseindia.net/jdbc
database problem - JDBCdatabase problem I installed Oracle 8.05 on Redhat 6.1 linux. If i fire up SQl plus seesion from the localhost, i can login succsfully as any user, If i go to a win98 or NT machine, I will get the following error after trying
problem of static in jsp page by multiple user accessproblem of static in jsp page by multiple user access hi ,
i am continuing my online exam project,but i have a Singleton class which i am invoking from my jsp page , ths page can
access by more number of users .every user
Problem in Jsp and database - Development processProblem in Jsp and database Hi, How can I reterive values from
database and display them in teextboxes so that when the user select the UPDATE... to the
database itself .
Thanks in advance. Hi Friend,
You can use
jfreechart display from access database data.jfreechart display from
access database data. I have made a
database... to retrieve the data from the
access database using prepared statement and then display... is to be done in a servlet..
Note that it is a
access made
database.
How can I
updation problem during transaction to ms-accessupdation
problem during transaction to ms-access Hey friends I am a beginner to java,and my
problem is related to updation query in ms-access.Actually have created a
database and through a jform button I am retrieving data
updation problem during transaction to ms-accessupdation
problem during transaction to ms-access Hey friends I am a beginner to java,and my
problem is related to updation query in ms-access.Actually have created a
database and through a jform button I am retrieving data
updation problem during transaction to ms-accessupdation
problem during transaction to ms-access Hey friends I am a beginner to java,and my
problem is related to updation query in ms-access.Actually have created a
database and through a jform button I am retrieving data
updation problem during transaction to ms-accessupdation
problem during transaction to ms-access Hey friends I am a beginner to java,and my
problem is related to updation query in ms-access.Actually have created a
database and through a jform button I am retrieving data
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 delete the access database value in jsphow to delete the
access database value in jsp i loaded my
database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from
database how to delete the access database value in jsphow to delete the
access database value in jsp i loaded my
database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from
database updating an access database with visual basic 2010updating an
access database with visual basic 2010 I am building a program in visual basic 2010 that connects to an
access database. I... the information is entered I need it to update the information in
access coding problem using vb and access - Securitycoding
problem using vb and access i have
problem on coding using vb on register button.when i click the label link it will terminate that program.so hard for me.i have no idea.
then i also have
problem on update,delete and add
problem in setting the values from databaseproblem in setting the values from database hello friends,
can anyone help me?? I am facing this
problem for past one week. I could't set the values from
database.
here is the code:
private JTextField getJTextField1
Problem in uploading image to to mysql databaseProblem in uploading image to to mysql database Hi, need some help... be save in the
database. and the image will also save in the desired folder. i have no
problem in saving the image in the folder, my
problem is it can't save
Problem in uploading image to to mysql databaseProblem in uploading image to to mysql database Hi, need some help... be save in the
database. and the image will also save in the desired folder. i have no
problem in saving the image in the folder, my
problem is it can't save
Extracting table from Access Database to ServletExtracting table from
Access Database to Servlet Sir,
I have a table with 4 field deptid, headid, normalexpend and projectexpend. Now I have...="h1".
The
problem is that I have 20 heads and 10 depts which means I'll have
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... and select the driver Microsoft
Access Driver(*.mdb).
3)After selecting the driver