I just started studying the connection between Java and SQL Server. I have created multiple accounts in my login_DB database. But only the first record results in a successful login.
My question is how do I make it accept the other accounts? I believe my problem is in the code but I'm weak at fixing logic errors. Here's my code:
try {
if(e.getSouce()==loginButton){
String user = usernameTF.getText().trim();
String pass = passwordTF.getText().trim();
String sqlLogin = "select username ,
pssword
from tblLogin
where username = '"+user+"'
and pssword = '"+pass+"'";
rs = st.executeQuery(sqlLogin);
int count = 0;
while(rs.next()){
count+=1;
}//while
if(count==1){
JOptionPane.showMessageDialog(null, "Login Successful!");
mainFrame.dispose();
firstPage page1 = new firstPage();
}
tblogin:
create table tblLogin ( username nvarchar(50) NULL, pssword nvarchar(50) NULL )
username password
Jerlon hello
buenconsejo jerlon
jujux jerlon
jujux jerlon
Buenconsejo jerlon
NULL NULL