/*PROGRAME TO DELETE DATA*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class Delete
{
public Delete() throws Exception
{
final JFrame jf = new JFrame("DELETE");
jf.setSize(600,500);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.getContentPane().setLayout(null);
Font f1 = new Font("sansserif",Font.BOLD,24);
Label l3 = new Label("ADDRESS BOOK");
l3.setBounds(200,10,800,40);
l3.setFont(f1);
jf.getContentPane().add(l3);
Label l = new Label ("DELETE BY NAME:");
l.setBounds(170,110,110,30);
jf.getContentPane().add(l);
final TextField tf = new TextField();
tf.setBounds(300,110,150,30);
jf.getContentPane().add(tf);
Label l1 = new Label ("TELEPHONE:");
l1.setBounds(170,160,100,30);
jf.getContentPane().add(l1);
final TextField tf1 = new TextField();
tf1.setBounds(300,160,150,30);
jf.getContentPane().add(tf1);
Button b1 = new Button("DELETE");
b1.setBounds(200,210,60,30);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
long s2,s5;
String s0,s6;
s0 = tf.getText();
s6=tf1.getText();
Connection cn;
Statement st;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbc:odbc:student");
st=cn.createStatement();
st.executeUpdate("Delete from addressb where name='"+s0+"'");
st.close();
}
catch(Exception e1){System.out.println("ERROR="+e1);
}
}
});
jf.getContentPane().add(b1);
Button b2 = new Button("ADD");
b2.setBounds(300,210,60,30);b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
Add a = new Add();
}
catch(Exception e2)
{}
}
});
jf.getContentPane().add(b2);
Button b3 = new Button("EXIT");
b3.setBounds(400,210,60,30);
b3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e2)
{
try
{
System.exit(0);
}
catch(Exception e3)
{}
}
});
jf.getContentPane().add(b3);
jf.show();
}
}
Sunday, September 23, 2007
DELETE DATA