hello can you help me when i click the add button it will not add to the database.it will generate an error..can you help me please hoping for your positive responds...here's my code,please see my attachment....
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JPanel.*;
import java.sql.*;
public class inqemployee extends JFrame implements ActionListener
{
JLabel Lidno,Ldate;
JLabel Lname,Llast,Lmiddle,Lposition;
JPanel p1,p2,p3,p4;
JRadioButton Rmale,Rfemale;
JButton badd,bexit,bsearch;
JTextField Tposition,Tdate,Tname,Tlast,Tmiddle,Tidno;
Connection con;
Statement st;
PreparedStatement ps;
public inqemployee()
{
super("Entry of Employee");
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int w = getSize().width;
int h = getSize().height;
int x = (dim.width-w)/3;
int y = (dim.height-h)/3;
setLocation(x,y);
Container pane = getContentPane();
pane.setLayout(new GridLayout(6,1));
setSize(380,350);
p1 = new JPanel();
p1.setLayout(new FlowLayout());
JTextField Tidno = new JTextField(10);
JTextField Tdate= new JTextField(10);
JTextField Tname = new JTextField(10);
JTextField Tlast = new JTextField(10);
JTextField Tmiddle= new JTextField(10);
Lidno = new JLabel("Id No. ");
Ldate = new JLabel ("Date Hired");
Lname = new JLabel("First Name ");
Llast = new JLabel("Last Name ");
Lmiddle= new JLabel("middle ");
p1.add(Tidno);
p1.add(Tdate);
p1.add(Lidno);
p1.add(Ldate);
pane.add(p1);
p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(Tname);
p2.add(Tlast);
p2.add(Tmiddle);
p2.add(Lname);
p2.add(Llast);
p2.add(Lmiddle);
pane.add(p2);
p3 = new JPanel();
p3.setLayout(new FlowLayout());
JTextField Tposition = new JTextField(10);
Rmale = new JRadioButton("male");
Rfemale = new JRadioButton("Female ");
Lposition = new JLabel("Position ");
p3.add(Tposition );
p3.add(Rmale);
p3.add(Rfemale);
pane.add(p3);
p3.add(Lposition);
p4 = new JPanel();
p4.setLayout(new FlowLayout());
// p4.setBorder(BorderFactory.createLineBorder(Color.red));
badd = new JButton("Add ");
badd.setMnemonic('A');
bexit= new JButton("Exit ");
bexit.setMnemonic('X');
bsearch = new JButton("Search");
bsearch.setMnemonic('S');
p4.add(badd);
p4.add(bexit);
p4.add(bsearch);
pane.add(p4);
badd.addActionListener(this);
bexit.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:eldenz");
}
catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null,"Class not Found","Not Found",JOptionPane.WARNING_MESSAGE);
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"Please Connect The Driver","Connect Sa Dong!",JOptionPane.WARNING_MESSAGE);
}
}
public void actionPerformed(ActionEvent e)
{
Object source = null;
source = e.getSource();
if (source == badd)
{
try
{
st = con.createStatement();
ps = con.prepareStatement("INSERT INTO Employee_tbl " + " (idno,lastname,firstname,middle,position,datehired)" + " VAlUES(?,?,?,?,?,?)");
ps.setString(1,Tidno.getText());
ps.setString(2,Tname.getText());
ps.setString(3,Tlast.getText());
ps.setString(4,Tmiddle.getText());
ps.setString(5,Tposition.getText());
ps.setString(6,Tdate.getText());
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"New record has been successfully added.","Record Added",JOptionPane.INFORMATION_MESSAGE);
st.close();
}
catch(SQLException sqlex)
{
JOptionPane.showMessageDialog(null,"Record have not been added");
}
}
if(source== bexit)
{
System.exit(0);
}
}
public static void main (String[] args)
{
new inqemployee();
}
}