Hello all,
Ive got a JFrame Login Form, a JFrame where i want to go after login, and a database with a table(1 row inserted). I want to get the login and the password out of the database table.
Ive made a class who loads the jdbc drivers, and connects with the database. And ive made another class for the query.
In the JFrame login form class ive done:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// HIER HEB IK CODE TOEGEVOEGD BIJ INLOGGEN BUTTON
boolean login = false;
String naam = Naam.getText();
String woord = Wachtwoord.getText();
login = this.businessManager.checkLogin(naam, woord);
if(login){
this.setVisible(false);
} else {
Error.setText("login failed");
}
}
And in the class with queries ive done:
public class BusinessManager {
public DatabaseManager dataManager;
public View_Main view;
public BusinessManager() {
dataManager = new DatabaseManager(this); // connect with the class where ive loaded the jdbc drivers and have connected to the database}
public boolean checkLogin(String name, String pass){
System.out.println("logincheck called, name="+name+" pass="+pass);
String sql = "SELECT username, password FROM KLANTEN";
if(name.equals("username") && pass.equals("password")){
return true;
} else {
return false;
}
}
My database table row looks like this:
CREATE TABLE KLANTEN(
user_id integer(10) NOT NULL,
username char(10) NOT NULL,
password integer NOT NULL,
abbonement1 char(10) NOT NULL,
abbonement2 char(10) NOT NULL,
openstaand decimal(4,2) NOT NULL,
PRIMARY KEY(user_id)
);
INSERT INTO KLANTEN
(user_id, username, password, abbonement1, abbonement2, openstaand)
VALUES
(1, 'name', 123123, 'geen', 'geen', 0);
The JFrame class where i want to go after login, has one JLabel. In this JLabel i want to put a String from the table of the database( like label.setText(String Text) ). The JFrame class is also connected to the class where i connect to the database
I also have another class whom has a main method, wherein i create the class with the JLabel like
new View_Main(businessManager);
The problem now is, that when i run the class with the main method, the login form comes out correctly, but when i type the username and password who are stored in the database table, this doesnt match(i think he cant read the database). What did i do wrong, is the query i made wrong? Then what must be done instead of String sql = "SELECT username, password FROM KLANTEN"; ? Can someone please help me with this?
public boolean checkLogin(String name, String pass){
System.out.println("logincheck called, name="+name+" pass="+pass);
String sql = "SELECT username, password FROM KLANTEN";
if(name.equals("username") && pass.equals("password")){
return true;
} else {
return false;
}
}