在 java 和 ms 访问中验证用户名和密码

validate username and password in java and ms access

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());
        } 
    }
}

您可能没有注意 密码 是一个保留字。因此:

PreparedStatement stm = con.prepareStatement("select * from login where username=? and [password]=?");