JDBC - Application 3

Store Data In  Table Student :

 
 

ResultSet rs = s.executeQuery(“select * from Student”);
While(rs.next())
{
    ta.append(rs.getString(1).trim( )+”\t”+rs.getInt(2)+”\t”+ rs.getString(3).trim( )+”\n”);
}

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class TableCreate3 implements ActionListener
{
    Statement s;
    Frame f;
    TextField tf1, tf2, tf3;
    Button b1, b2, b3, b4;
    Dialog d;
    Label l;
    Panel p;
    String s1, s2, s3;
    int a;
    TextArea ta;
    ResultSet rs;
    TableCreate3()
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection c = DriverManager.getConnection("Jdbc:Odbc:Maya");
            s = c.createStatement();
           
            f = new Frame();
            tf1 = new TextField(10);
            tf2 = new TextField(10);
            tf3 = new TextField(10);
            b1 = new Button("INSERT");
            b2 = new Button("OK");
            b3 = new Button("CANCEL");
            b4 = new Button("VIEW");
            d = new Dialog(f,"Inserting Data?");
            l = new Label();
            p = new Panel();
            ta = new TextArea(20,20);
            f.setLayout(new FlowLayout());
            f.add(tf1);
            f.add(tf2);
            f.add(tf3);
            f.add(b1);
            p.add(l);
            p.add(b2);
            p.add(b3);
            d.add(p);
            d.setSize(250,250);
            b1.addActionListener(this);
            b2.addActionListener(this);
            b3.addActionListener(this);
            b4.addActionListener(this);
            f.setSize(400,400);
            f.setVisible(true);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource() == b1)
        {
            s1 = tf1.getText();
            s2 = tf2.getText();
            s3 = tf3.getText();
            a = Integer.parseInt(s2);
            l.setText("Name : "+s1+"Id : "+a+"Address : "+s3);
            d.setVisible(true);
        }
        if(e.getSource() == b2)
        {
            try
            {
                s.execute("insert into Student values('"+s1+"',"+a+",'"+s3+"')");
                System.out.println("inserted");
                tf1.setText("");
                tf2.setText("");
                tf3.setText("");
                d.setVisible(false);
                f.add(b4);
                f.add(ta);
            }
            catch(Exception ce)
            {
                ce.printStackTrace();
            }
        }
        if(e.getSource() == b3)
        {
            d.setVisible(false);
        }
        if(e.getSource() == b4)
        {
            try
            {
                rs = s.executeQuery("select * from Student");
                while(rs.next())
                {
    ta.append(rs.getString(1).trim()+"\t"+rs.getInt(2)+"\t"+rs.getString(3).trim()+"\n");
                }
            }
            catch(Exception ce1)
            {
                ce1.printStackTrace();
            }
        }
        f.repaint();
        f.validate();
    }
    public static void main(String[] args)
    {
        TableCreate3 x = new TableCreate3();
    }
}