Java ile Login İşlemi

dologin methoduna göndereceğiniz username ve password değeri boolean olarak duruma göre geri dönüş sağlamaktadır size.

public class baglan {
    public static Connection con = null;
    private static String url = "jdbc:mysql://localhost:3306/otel";
    private static String driver = "com.mysql.jdbc.Driver";
    private static String username = "root";
    private static String password = "root";
    static ResultSet rs = null;
    public static int userid;
    public static int girisTip;
    public static void openConnection(){
        try {
            Class.forName(driver).newInstance();
            con = (Connection) DriverManager.getConnection(url,username,password);
        } catch (Exception ex) {
            Logger.getLogger(baglan.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public static boolean doLogin(String username, String password){
        baglan.openConnection();
        try {
            PreparedStatement ps = (PreparedStatement) baglan.con.prepareStatement("select sifre,id,tip from uyeler where kuladi=?");
            ps.setString(1, username);
            rs=ps.executeQuery();
            if(rs.next()){
                String pw = rs.getString("sifre");
                if(password.equals(pw)){
                    userid = rs.getInt("id");
                    girisTip = rs.getInt("tip");
                    return true;
                }
            }
        } catch (SQLException ex) {
            Logger.getLogger(baglan.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return false;
    }
}


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Other Entries

Kategoriler