2018即将到来,又是伤感来句,“流浪的人在外想念你,亲爱的妈妈”。祝愿自己在新的一年里学业有成,心想事成,祝愿爸爸妈妈身体健康,生意兴隆也祝愿黑马越办越好。今天学习了常量池的知识,要多导入jar包,最后就是用数据库的知识和JAVA结合做了关于一个登陆,注册的案例
public class UserOperator {
private static QueryRunner qr =new QueryRunner(JDBCUtils.getDataSource());
private static Scanner sc =new Scanner(System.in);
public static String chooser() {
System.out.println("欢迎光临");
System.out.println("请选择功能菜单");
System.out.println("1 登陆 2注册 3 退出");
return sc.nextLine();
}
public static void main(String[] args) {
UsersDao dao = new UsersDao();
while (true) {
String num =chooser();
switch (num) {
case "1":
System.out.println("选择登陆,请输入用户名");
String username =sc.nextLine();
System.out.println("请输入密码");
String password =sc.nextLine();
boolean b = dao.login(username, password);
if(b)
System.out.println("登陆成功");
else
System.out.println("登陆失败,请检查你的用户名和密码");
break;
case "2":
System.out.println("选择注册,请输入用户名");
username =sc.nextLine();
System.out.println("请输入密码");
password =sc.nextLine();
b = dao.register(username, password);
if(b)
System.out.println("注册成功");
else
System.out.println("注册失败,用户名已被占用,请尝试"+username+"_123");
break;
case "3":
System.out.println("退出");
System.exit(0);
default:
break;
}
里面还有关于登陆和注册的代码的,数据库的一个查询和增。
|
|