用户名和密码的登陆

Posted 苏轼的红烧肉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用户名和密码的登陆相关的知识,希望对你有一定的参考价值。

package com.lianxi;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class TestSign {

    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/boooks","root","tiger");
        Statement st=conn.createStatement();
        Scanner s=new Scanner(System.in);    
        System.out.println("用户名");
        String name=s.nextLine();
        System.out.println("密码");
        String pwd=s.nextLine();
        
        ResultSet rs=st.executeQuery("select * from tb_user  where userName=‘"+name+"‘ and password=‘"+pwd+"");
        if(rs.next()){
            System.out.println("登陆成功");
        }else{
            System.out.println("用户名或密码错误");
        }
        rs.close();
        st.close();
        conn.close();

    }

}

 

以上是关于用户名和密码的登陆的主要内容,如果未能解决你的问题,请参考以下文章