2016-04-10 13 views
-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()); 
     } 
    } 
} 
+1

質問をするのを忘れました。 – Pshemo

答えて

0

パスワードは予約語です。したがって:

PreparedStatement stm = con.prepareStatement("select * from login where username=? and [password]=?"); 
関連する問題