-2
import java.sql.*;
import java.util.*;

class Check {
    public static void main(String[] args)               
    {
        try   
        {
            String username;
            String password;
            System.out.println("Enter username and password");
            Scanner s=new Scanner(System.in);
            username=s.next();
            password=s.next();
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
            Connection con=DriverManager.getConnection("jdbc:odbc:logindetails");
            PreparedStatement stm=con.prepareStatement("select*from login where username=?and password=?"); 
            stm.setString(1,username); 
            stm.setString(2,password);
            int result=stm.executeUpdate();
            if (result==1)
            {
                System.out.println("login success"); 
            }      
            else
            {
                System.out.println("login failed");
            }
            con.close();
        } 
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        } 
    }
}
Pshemo
  • 122,468
  • 25
  • 185
  • 269

1 Answers1

0

You probably miss to take care for that password is a reserved word. Thus:

PreparedStatement stm = con.prepareStatement("select * from login where username=? and [password]=?"); 
Gustav
  • 53,498
  • 7
  • 29
  • 55