6.Data Insertion with Access


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

public class AddEmployee extends JFrame implements ActionListener
{

JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,wall;
JTextField t1,t2,t3,t4,t5,t6,t7;
JTextArea ta;
JButton b1,b2,b3;
JComboBox cb1,cb2;

public AddEmployee()
{
//———back—————-
wall=new JLabel(“”);
wall.setIcon(new ImageIcon(“1.jpg”));
add(wall);

//—————-Label———————
l1=new JLabel(“PentaSquare Agency”);
l1.setBounds(120,10,340,20);
l1.setFont(new Font(“Algerian”,Font.BOLD,25));
l1.setForeground(new Color(98,83,140));

l2=new JLabel(“Add Employee”);
l2.setBounds(250,50,200,20);
l2.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l2.setForeground(new Color(69,23,10));

l3=new JLabel(“Date :”);
l3.setBounds(20,80,80,30);
l3.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l3.setForeground(new Color(50,53,60));

l4=new JLabel(“Employee Name :”);
l4.setBounds(50,120,150,30);
l4.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l4.setForeground(new Color(50,53,60));

l5=new JLabel(“Contact no :”);
l5.setBounds(50,160,150,30);
l5.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l5.setForeground(new Color(50,53,60));

l6=new JLabel(“Address :”);
l6.setBounds(50,200,150,30);
l6.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l6.setForeground(new Color(50,53,60));

l7=new JLabel(“Email-ID :”);
l7.setBounds(50,330,150,30);
l7.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l7.setForeground(new Color(50,53,60));

l8=new JLabel(“Date of Birth :”);
l8.setBounds(50,370,150,30);
l8.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l8.setForeground(new Color(50,53,60));

l9=new JLabel(“Maritual Status :”);
l9.setBounds(50,410,150,30);
l9.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l9.setForeground(new Color(50,53,60));

l10=new JLabel(“Qualification :”);
l10.setBounds(50,450,150,30);
l10.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l10.setForeground(new Color(50,53,60));
l11=new JLabel(“Date of Joining :”);
l11.setBounds(50,490,150,30);
l11.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l11.setForeground(new Color(50,53,60));
l12=new JLabel(“Referance :”);
l12.setBounds(50,530,150,30);
l12.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
l12.setForeground(new Color(50,53,60));
//————–TextBox——————–
t1=new JTextField(10);
t1.setBounds(100,80,80,30);

t2=new JTextField(10);
t2.setBounds(200,120,150,30);

t3=new JTextField(10);
t3.setBounds(200,160,150,30);

t4=new JTextField(10);
t4.setBounds(200,330,150,30);

t5=new JTextField(10);
t5.setBounds(200,370,150,30);

t6=new JTextField(10);
t6.setBounds(200,490,150,30);

t7=new JTextField(10);
t7.setBounds(200,530,150,30);
//—————–TextArea———————
ta=new JTextArea(5,5);
ta.setBounds(200,200,130,120);
//——————Button—————–
b1=new JButton(“Save”);
b1.setBounds(100,570,80,30);
b1.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
b1.setForeground(new Color(10,133,10));

b2=new JButton(“Reset”);
b2.setBounds(190,570,80,30);
b2.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
b2.setForeground(new Color(10,133,10));

b3=new JButton(“Close”);
b3.setBounds(280,570,80,30);
b3.setFont(new Font(“Freestyle Script”,Font.BOLD,25));
b3.setForeground(new Color(10,133,10));

//———ComboBox—————-
cb1=new JComboBox();
cb1.addItem(“Select”);
cb1.addItem(“SSC”);
cb1.addItem(“HSC”);
cb1.addItem(“Diploma”);
cb1.addItem(“Degree”);
cb1.addItem(“MCA”);
cb1.setBounds(200,450,150,30);

cb2=new JComboBox();
cb2.addItem(“Select”);
cb2.addItem(“Male”);
cb2.addItem(“Female”);
cb2.setBounds(200,410,80,30);
//——————————————-
add(l1);
add(l2);
add(l3);add(t1);
add(l4);add(t2);
add(l5);add(t3);
add(l6);add(ta);
add(l7);add(t4);
add(l8);add(t5);
add(l9);add(cb1);
add(l10);add(cb2);
add(l11);add(t6);
add(l12);add(t7);
add(b1);add(b2);add(b3);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);

setLayout(null);
setSize(600,700);
setVisible(true);
setTitle(“Add Employee”);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
Connection conn=null;
PreparedStatement stmt=null;
ResultSet rs=null;

String Dates=t1.getText();
String Employeename=t2.getText();
String Contactno=t3.getText();
String Address=ta.getText();
String Email=t4.getText();
String Birth=t5.getText();
String Maritaulstatus=(String)cb2.getSelectedItem();
String Qualification=(String)cb1.getSelectedItem();
String Joining=t6.getText();
String Reference=t7.getText();

try
{
String sql1=”insert into Employeedetail(Dates1,Employeename1,Contactno1,Address1,Email1,Birth1,MSATUS1,Qualification1,Joining1,Reference1) values(?,?,?,?,?,?,?,?,?,?)”;
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
conn= DriverManager.getConnection(“jdbc:odbc:mydsn”,”Realestate”,”bca”);
stmt=conn.prepareStatement(sql1);

stmt.setString(1,Dates);
stmt.setString(2,Employeename);
stmt.setString(3,Contactno);
stmt.setString(4,Address);
stmt.setString(5,Email);
stmt.setString(6,Birth);
stmt.setString(7,Maritaulstatus);
stmt.setString(8,Qualification);
stmt.setString(9,Joining);
stmt.setString(10,Reference);
stmt.executeUpdate();
System.out.println(“Record inserted Successfully”);
}catch (Exception e)
{
System.out.println(“error”+e);
}
}
if(ae.getSource()==b2)
{

t1.setText(“”);
t2.setText(“”);
t3.setText(“”);
ta.setText(“”);
t4.setText(“”);
t5.setText(“”);
cb1.setSelectedItem(“Select”);
cb2.setSelectedItem(“Select”);
t6.setText(“”);
t7.setText(“”);

}

if(ae.getSource()==b3)
{
dispose();
}

}
public static void main(String args[])throws SQLException
{
new AddEmployee();
}
}