You are on page 1of 5

import java.awt.

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

public class College implements ActionListener 


{

 Panel p;
 Frame f;
 Button b1,b2,b3,b4,b5,b6,b7;
 TextField tf1,tf2,tf3,tf4,tf5,tf6,tf7;
 Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15;
 GridLayout gl;
 Connection con;
 Statement st;
 String s1,s2,s3,s4,s5,s6,s7,sr1,sr2;
 TextArea ta1;
 College()
 {
  f=new Frame(); 
  p=new Panel();
  p.setBackground(Color.cyan);
  gl=new GridLayout(31,8,3,3);
  p.setLayout(gl);
  b1=new Button("Insert");
  b1.addActionListener(this);
  
  b2=new Button("Select");
  b2.addActionListener(this);
  
  b3=new Button("Select");
  b3.addActionListener(this);
  
  b4=new Button("Results");
  b4.addActionListener(this);
  b5=new Button("Select");
  b5.addActionListener(this);
  b6=new Button("Exam");
  b6.addActionListener(this);
  b7=new Button("Submit");
  b7.addActionListener(this);
  tf1=new TextField(50);
  tf1.setBackground(Color.yellow);
  tf2=new TextField(10);
  tf2.setBackground(Color.yellow);
  tf3=new TextField(50);
  tf3.setBackground(Color.yellow);
  tf4=new TextField(20);
  tf4.setBackground(Color.yellow);
  tf5=new TextField(6);
  tf5.setBackground(Color.yellow);
  tf6=new TextField(10);
  tf6.setBackground(Color.yellow);
  tf7=new TextField(10);
  tf7.setBackground(Color.yellow);
  tf8=new TextField(10);
  tf8.setBackground(Color.yellow);
  ta1=new TextArea(10,2);
  l1=new Label("Enter student info");
  l2=new Label("Update student info");
  l3=new Label("View student info");
  l4=new Label("View results");
  l5=new Label("Delete student info");
  l6=new Label("View exam details");
  l7=new Label("Name");
  l8=new Label("Roll");
  l9=new Label("Address");
  l10=new Label("Phone");
  l11=new Label("E-Mail");
  l12=new Label("Gender");
  l13=new Label("Date of Birth");
  l14=new Label("Result");
  l15=new Label("Exam Details");
  p.add(l1);p.add(b1);p.add(l2);p.add(b2);p.add(l3);p.add(b3);p.add(l4);p.add(b4);p.add(l5);p.add
(b5);p.add(l6);p.add(b6);
  p.add(l7);p.add(tf1);p.add(l8);p.add(tf2);p.add(l9);p.add(tf3);p.add(l10);p.add(tf4);p.add(l11);p.a
dd(tf5);p.add(l12);p.add(tf6);p.add(l13);p.add(tf7);p.add(b7);p.add(l14);p.add(tf8);p.add(l15);p.ad
d(ta1);
  f.add(p);
  f.setSize(100,200);
  f.setVisible(true);
  }
 public void actionPerformed(ActionEvent e)
 {
 
if(e.getSource()==b1)
 {
try
{
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   con=DriverManager.getConnection("jdbc:odbc:Avishek");
   s1=tf1.getText();
   s2=tf2.getText();
   s3=tf3.getText();
   s4=tf4.getText();
   s5=tf5.getText();
   s6=tf6.getText();
   s7=tf7.getText();
   st=createStatement.executeQuery("insert into Table1 values(?,?,?,?,?,?,?)");
  
   st.setString(1,s1);
   st.setString(2,s2);
   st.setString(3,s3);
   st.setString(4,s4);
   st.setString(5,s5);   
   st.setString(6,s6);
   st.setString(7,s7);

   st.executeUpdate();
   st.execute();

  
  st.close();
 }
 catch(Exception i)
 {
 System.out.println("Error");
 }
}
 
   if(e.getSource()==b2)
   {
 try
 {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   con=DriverManager.getConnection("jdbc:odbc:Avishek");   
   s1=tf1.getText();
   s2=tf2.getText();

   st=createStatement.executeQuery("update Table1 set Name=?"+"where Roll=?");


   st.setString(1,s1);
   st.setString(2,s2);
   
   st.executeUpdate();
   st.execute();
  
  st.close();
 }
  catch(Exception i)
  {
   System.out.println("Error");
  }
 }
 
   if(e.getSource()==b3)
   {
   try
    {
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con=DriverManager.getConnection("jdbc:odbc:Avishek");
     ResultSet rs=con.createStatement("Select * from Table1");
while(rs.next())
{

 String s1=rs.Name;
 String s2=rs.Roll;
 String s3=rs.Address;
 String s4=rs.Phone;
 String s5=rs.E-Mail;
 String s6=rs.Gender;
 String s7=rs.Date Of Birth;
 tf1.setText(s1);
 tf2.setText(s2);
 tf3.setText(s3);
 tf4.setText(s4);
 tf5.setText(s5);
 tf6.setText(s6);
 tf7.setText(s7);
 

}
     
      
      rs.close();
     }

  catch(Exception i)
  {
   System.out.println("Error");
  }
 }
 if(e.getSource()==b4)
   {
   try
    {
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con=DriverManager.getConnection("jdbc:odbc:Avishek");
     s2=tf2.getText();
      
     ResultSet rs1=con.createStatement("select from Result where SRoll=?");
     while(rs.next())
    {
     if(s2.equals(Roll))     
     {
      String sr1=rs.SRoll;
      String sr2=rs.SResult;
      tf2.setText(sr1);
      tf8.setText(sr2);
     
     }
   }   
   rs.close();
     

  catch(Exception i)
  {
   System.out.println("Error");
  }
 }
 if(e.getSource()==b5)
   {
   try
    {
     s2=tf2.getText();
     st=createStatement.executeQuery("delete from Somu where Roll=?");
     st.setString(2,Roll); 
     st.executeUpdate();
     st.execute();
     
     st.close();
     }

  catch(Exception i)
  {
   System.out.println("Error");
  }
 }
  if(e.getSource()==b6)
   {
    String exam="\nB-Tech 1st sem starts 12.2.2010.\n"+
                "\nB-Com 1st sem starts 10.2.2010.\n"+
                "\nMBA 1st sem starts 15.2.2010.\n";
    ta1.setText(exam);    
      
     } 
  

}
 public static void main(String args[])
 {
  College c=new College(); 
 }
}

You might also like