首页 > 代码库 > 登入界面的创建
登入界面的创建
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
//登入
public class Demo2 {
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
ResultSet rset = null;
String url = "jdbc:mysql:///eqet";
String user = "root";
String password = "root";
Scanner input = new Scanner(System.in); //手动输入
System.out.println("\t 个人用户管理");
System.out.print("请登入账号:");
String name = input.next();
System.out.print("请登入密码:");
String password1 = input.next();
try {
Class.forName("com.mysql.jdbc.Driver");//加载驱动
connection =DriverManager.getConnection(url, user, password);//连接对象
statement = connection.createStatement();//获取Statement对象
String sql = "SELECT * FROM master WHERE name=‘"+name+"‘ AND Password = ‘"+password1+"‘";
rset = statement.executeQuery(sql);//查询
if (rset.next()) {
System.out.println("登入成功");
}else{
System.out.println("登入失败");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {//关闭资源 切记一定要 先开的后关,后开的先关
if (null!=rset) {
rset.close();
}
if(null!=statement){
statement.close();
}
if (null!=connection) {
connection.close();
}
} catch (Exception e2) {
}
}
}
}
登入界面的创建