jdbc 06: 实现登陆页面
jdbc连接mysql,实现简单的登陆验证
package com.examples.jdbc.o6_实现登录界面;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Scanner;
/*
jdbc实现用户登录界面
*/
public class Test {
public static void main(String[] args) {
//用户登录
Map<String, String> userInfo = userLogin();
//验证登录信息
boolean loginResult = loginCheck(userInfo);
System.out.println(loginResult ? "登录成功" : "登录失败");
}
/**
* 登录信息验证
* @param userInfo 用户输入的用户名,密码
* @return 登录信息检测结果,通过验证:true, 未通过验证:false
*/
private static boolean loginCheck(Map<String, String> userInfo) {
boolean loginResult = false;
String name = userInfo.get("userName");
String passwd = userInfo.get("passWord");
//jdbc连接数据库进行登录验证
//资源绑定器绑定数据库配置信息
ResourceBundle resourceBundle = ResourceBundle.getBundle("config/jdbc");
String driver = resourceBundle.getString("driver");
String url = resourceBundle.getString("url");
String userName = resourceBundle.getString("userName");
String passWord = resourceBundle.getString("passWord");
//3个资源
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
//1.
Class.forName(driver);
//2.
connection = DriverManager.getConnection(url, userName, passWord);
//3.
statement = connection.createStatement();
//4.
String sql = "select * from tb_user where uname = '"+name+"' and upasswd = '"+passwd+"'";
resultSet = statement.executeQuery(sql);
if(resultSet.next()){
loginResult = true;
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
} finally {
//6.
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return loginResult;
}
/**
* 用户登录
* @return 用户名,用户密码
*/
private static Map<String, String> userLogin() {
Scanner scanner = new Scanner(System.in);
System.out.println("用户名: ");
String userName = scanner.nextLine();
System.out.println("密码: ");
String passWord = scanner.nextLine();
Map<String, String> userInfo = new HashMap<>();
userInfo.put("userName", userName);
userInfo.put("passWord", passWord);
return userInfo;
}
}
jdbc 06: 实现登陆页面的更多相关文章
- 修改cas登陆页面-服务器端
原文地址:http://www.cnblogs.com/liveandevil/archive/2013/03/06/2946341.html 1.cas统一认证的登陆页面位于:cas目录/WEB-I ...
- Springsecurity3.1.3配置多个登陆页面
需求:网站的前台和后台不同的url需要不同的登陆页面,不同的异常捕获方式. spring-security3.1以后的版本支持多个<http>标签,因此本文所采用的方式就是使用两个,实际上 ...
- MUI APP防止登陆页面出现白屏
最近在用MUI开发APP,总体效果,在IOS上,是完美的,但是在低端的Android手机上,就会出现性能问题,我个人觉得最严重的是,就是首页,就是APP打开的第一个页面,在iOS上,由于性能高,所以, ...
- web系统登陆页面增加验证码
传统登陆页面中包含两个输入项: • 用户名 • 密码有时为了防止机器人进行自动登陆操作,或者防止恶意用户进行用户信息扫描,需增加动态验证码功能.此时,登陆页面中包含了三个输入项: • 用户名 • 密码 ...
- Ajax 提交session实效跳转到完整的登陆页面
在spring security 中 Ajax提交时,session超时,局部加载登陆页面,为解决这个问题,重写ajax提交,返回的是modeview或者没有制定datatype时; 如果检测到加载到 ...
- js实现登陆页面的拖拽功能
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>登 ...
- iOS 本地加载html登陆页面
Html的代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- Struts2文件配置 登陆页面
Struts 版本号 struts-2.3.16.3 web.xml 配置 <?xml version=”1.0″ encoding=”UTF-8″?> <web-app versi ...
- .Net程序猿玩转Android开发---(3)登陆页面布局
这一节我们来看看登陆页面如何布局.对于刚接触到Android开发的童鞋来说.Android的布局感觉比較棘手.须要结合各种属性进行设置,接下来我们由点入面来 了解安卓中页面如何布局,登陆页面非常eas ...
随机推荐
- [笔记] 轮廓线 DP
是状态 DP 的一种,主要是对于网格图状压,实现 \(O(1)\) 转移的一种处理方式. oooo---- ----x - 是状压了信息的位置,x 是当前更新的位置. 应用价值 可以一格一格考虑状态, ...
- 「BUAA OO Unit 2 HW8」第二单元总结
「BUAA OO Unit 2 HW8」第二单元总结 目录 「BUAA OO Unit 2 HW8」第二单元总结 Part 0 前言 Part 1 第五次作业 1.1 作业要求 1.2 架构设计 1. ...
- 如何形象简单地理解java中只有值传递,而没有引用传递?
首先,java中只有值传递,没有引用传递.可以说是"传递的引用(地址)",而不能说是"按引用传递". 按值传递意味着当将一个参数传递给一个函数时,函数接收的是原 ...
- 渗透:EWSA
EWSA全称Elcomsoft Wireless Security Auditor.ElcomSoft是一家俄罗斯软件公司,出品过不少密码破解软件,涉及Office.SQL.PDF.EFS等等. EW ...
- Spring 源码(16)Spring Bean的创建过程(7)属性填充
知识回顾 上一篇介绍了Spring中三级缓存的singletonObjects.earlySingletonObjects.singletonFactories,Spring在处理循环依赖时在实例化后 ...
- chkconfig-配置系统服务
管理Linux系统开机启动项. chkconfig命令默认在CentOS7+中不被使用了,由于系统服务管理都交给了systemctl托管. 语法 chkconfig [--list] [--type ...
- Es6语法+v-on参数相关+vue虚拟dom
Es6的语法 Es5:if和for 都没有块级作用域,函数function有作用域. Es6:加入let使得if和for有作用域 .建议: 在Es6中优先使用const,只有需要改变某一个标识符的时候 ...
- 《Mybatis 手撸专栏》第10章:使用策略模式,调用参数处理器
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 你这代码写的,咋这么轴呢! 说到轴,让我想起初中上学时老师说的话:"你那脑 ...
- Unicode和中午互转
import java.io.UnsupportedEncodingException; public class TestUnicode{ /* * 中文转unicode编码 */ public s ...
- C#获取PLC信息 (KepServer)二
具体应用呢,不多说了,上代码,取长补短就是原创 using OPCAutomation; using System; using System.Collections.Generic; using S ...