import java.sql.*;
import javax.sql.*;
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class Display extends JFrame implements ActionListener
{
JLabel l1;
JTextField t1,t2;
JButton b1,b2;
public Display(String s)
{
super(s);
l1 = new JLabel("user name");
b1 = new JButton("submit");
b2 = new JButton("reset");
t1 = new JTextField(20);
t2 = new JTextField(20);
Panel p = new Panel();
p.setLayout(new GridLayout(2,2));
p.add(l1);
p.add(t1);
p.add(b1);
p.add(b2);
p.add(t2);
add(p);
b1.addActionListener(this);
b2.addActionListener(this);
}
public static void main(String args[])
{
Display d = new Display("main frame");
d.setVisible(true);
d.setSize(300,300);
}
public void actionPerformed(ActionEvent ae)
{
String k;
String m="";
k = ae.getActionCommand();
if(k=="submit" )
{
String x = t1.getText();
Connection conn;
ResultSet r =null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:aanchal");
Statement stmt = conn.createStatement();
r =stmt.executeQuery("select * from id");
while (r.next())
{
m = r.getString(1);
System.out.println(m);
try{
if(x.equals("m"))
{
t2.setText("authenticated");
}
else
{
t2.setText("invalid");
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
r.close();
stmt.close();
conn.close();
}
catch (ClassNotFoundException e)
{
System.out.println( e.getMessage());
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
else if(k=="reset")
{
t1.setText("");
t2.setText("");
}
}
}
Aanchal89 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.