hello again!
I have a log in box and I'm trying to verify that the password the user enters is correct by comparing it to his/her password held in a database.
Here is my code:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class Staff extends Panel implements ActionListener
{
private TextField id=new TextField(20);
private TextField pas=new TextField(20);
private Button submit=new Button("Submit");
private Button nonvalid=new Button("Wrong password. Please try again");
private Label instruction=new Label ("Please enter your I.D and password");
public void setEchoChar(char c)
{pas.setEchoChar('#');
}
public Staff()
{
add(id);
add(pas);
pas.setEchoChar('#');
add(instruction);
add(submit);
submit.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == submit)
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url, user, password;
url ="jdbc
dbc:STUDENT";
user = "MSC030";
password = "bagpuss";
Connection conn =DriverManager.getConnection(url, user, password);
String sta=id.getText();
String spass=pas.getText();
String query="SELECT PASSWORD FROM MSC030.STAFF WHERE STAFF_NO="+ sta;
ResultSet theResult;
Statement stmt=conn.createStatement();
theResult=stmt.executeQuery(query);
String valid=theResult.getString("PASSWORD");
if (valid.equals(spass))
{
System.out.print ("hi");
}
else
{add(nonvalid);
}
}
catch(SQLException s)
{System.out.print("SQL Error:" +s.toString() + "" + s.getErrorCode() + "" + s.getSQLState());
}
catch(ClassNotFoundException s)
{System.out.print("Class not found");
}
}
}
I am unable to get the code working: There is no compiling error and nothing happens on the screen when I press 'Submit'
Could anyone help??
Thank you