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());
}
}
}
Asked
Active
Viewed 794 times
-2

Pshemo
- 122,468
- 25
- 185
- 269

kanivalan vp
- 3
- 1
-
1You forgot to ask question. – Pshemo Apr 10 '16 at 13:29
1 Answers
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