hello there
this is my current school project assignment. i have made a db to login but am stuck. I have three class. can someone tell me why am stuck and how to fix it. here is my appMain where the program run from
the appMain
package ElectronicRole;
/**
*
* @author luanataylor
*/
public class AppMain {
public static void main(String args[]) {
/* Set the Nimbus look and feel */
Login logscrn = new Login();
logscrn.setVisible(true);
while(!logscrn.isLoginValid()){
//do nothing
}
if(logscrn.getUserType().equals("STUDENT")){
StudentHomePage shp = new StudentHomePage();
shp.setVisible(true);
}
else if( logscrn.getUserType().equals("LECTURER")){
LecturerHomePage lhp = new LecturerHomePage();
lhp.setVisible(true);
}
logscrn.setVisible(false);
}
}
here is the login, the interface
package ElectronicRole;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
public class Login extends javax.swing.JFrame implements ActionListener {
private boolean isLoginValid;
public Login() {
initComponents();
this.isLoginValid = false;
}
public String getUserType(){// this method is being used to check the usertype, whether it is either the student or lecturer
//this codes here is to check to see if it is the lecturer or the student
int i = jBoxselect.getSelectedIndex();
String UserType ="";
if(i == 0){ // this is checking to see which user will be login
UserType = "STUDENT";
}
else
if(i == 1){
UserType = "LECTURER";
}
return UserType;
}
public boolean validateLogin(){
//this checking to see if the userid, password and usertype is valid or not
Model model = new Model();
HashMap <String, String > login = new HashMap<String, String>(); // values are pass to the ash map
login.put("userid",txtuserid.getText());
login.put("password", pass.getText());
login.put("usertype", this.getUserType());
return model.isLoginValid(login);
}
// check to see if the login is valid or not and if it is, the user can login
public boolean isLoginValid(){
return this.isLoginValid;
}
@Override
public void actionPerformed(ActionEvent ae){
if("Ok".equals(ae.getActionCommand())){
Object src = ae.getSource();
if(src.equals("Ok")){
}
}
}
this is the dbcon class
package ElectronicRole;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author luanataylor
*/
public class DBCon {
public DBCon(){
}
public Connection connect(){
Connection conn =null;
try{
//connecting to the db
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("dbc.sql://localhost:3306/electronicrole", "dbuser", "dbpass");
}
catch(Exception e){
System.out.println(e);
}
return conn;
}
public Statement statement(){
Statement stmt=null;
try {
stmt = this.connect().createStatement();
} catch (SQLException ex) {
}
return stmt;
}
public ResultSet executeQuery(String querystr) {
ResultSet rs =null;
try{
rs = this.statement().executeQuery(querystr);
}
catch(SQLException e){
System.out.println(e);
}
return rs;
}
and this is my model class
public class Model extends DBCon {
ResultSet rs;
public boolean isLoginValid(HashMap <String, String> login) {
boolean valid = false;
String querystr, table;
//check for the usertype if it is equal to student when check for the login
if( login.get("usertype").equals("STUDENT")){
table = "students";
}
else{
table = "lecturers";// it is not the students, it will be the lecturer
}
querystr = String.format("SELECT COUNT(StudentID) AS count FROM %s WHERE StudentID=\"%s\" AND Password=\"%s\"", table, login.get("userid"),login.get("password"));
System.out.println(querystr);
try {
this.rs = this.executeQuery(querystr);
rs.next();
if(rs.getInt("count") > 0){
valid = true;
}
}
catch(SQLException e){
}
return valid;
}
}

