Sunday, September 23, 2007

SEARCH DATA

/*PROGRAME TO SEARCH PARTICULAR DATA*/



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class Search
{
public Search()
{
final JFrame jf = new JFrame("Search");
jf.setSize(800,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(250,10,800,40);
l3.setFont(f1);
jf.getContentPane().add(l3);
final TextArea ta = new TextArea();
ta.setBounds(0,120,1000,600);
ta.setEditable(false);
jf.getContentPane().add(ta);
Label l = new Label ("SEARCH BY NAME:");
l.setBounds(5,60,110,30);
jf.getContentPane().add(l);
final TextField tf = new TextField();
tf.setBounds(130,60,100,30);
jf.getContentPane().add(tf);
Label l1 = new Label ("TELEPHONE:");
l1.setBounds(250,60,100,30);
jf.getContentPane().add(l1);
final TextField tf1 = new TextField();
tf1.setBounds(350,60,100,30);
jf.getContentPane().add(tf1);
Button b1 = new Button("SEARCH");
b1.setBounds(480,60,60,30);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String s6,s,s1,s3,s4,d,s0="1233";
long s2,s5;
s = tf.getText();
s6=tf1.getText();
if(s6.equals(""))
s5=Long.parseLong(s0);
else
s5 = Long.parseLong(tf1.getText());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
final Connection con =DriverManager.getConnection("jdbc:odbc:student");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * From addressb");
while(rs.next())
{
s1 = rs.getString(1);
s2 = rs.getLong(2);
s3 = rs.getString(3);
s4 = rs.getString(4);
d = rs.getString(5);
System.out.println("gotstring");
if((s1.equals(s))||(s2==s5))
{
System.out.println("string equal");
ta.append("NAME : "+s1+"\n");
ta.append("PHONE NO : "+s2+"\n");
ta.append("ADDRESS : "+s3+"\n");
ta.append("EMAIL ID : "+s4+"\n");
ta.append("DATE OF BIRTH : "+s5+"\n");
ta.append("**************************************"+"\n");
}
}
}
catch(Exception e1){System.out.println("ERROR="+e1);
}
}
});
jf.getContentPane().add(b1);
Button b2 = new Button("ADD");
b2.setBounds(550,60,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");
Button b4 = new Button("DELETE");
b4.setBounds(620,60,60,30);
b4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e4)
{
try
{
Delete d = new Delete();
}
catch(Exception e5){}
}
});
jf.getContentPane().add(b4);
b3.setBounds(690,60,60,30);
b3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e2)
{
try
{
System.exit(0);
}
catch(Exception e3){}
}
});
jf.getContentPane().add(b3);
jf.show();
}
}