📄 operationlogin.java
字号:
package edu.scau.login;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import edu.scau.database.DBUtil;
public class OperationLogin {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
OperationLogin ol = new OperationLogin();
// System.out.println(ol.login("001", "001"));
}
/**
*
* @param name
* @param pwd
* @return
*/
public boolean login(String number, String pwd) {
boolean b = false;
Connection conn = null;
String getPasswordByName = null;
Statement sm = null;
ResultSet rs = null;
DBUtil dbUtil = new DBUtil();
try {
// 1.获取数据库连接
conn = dbUtil.getConn();
// 2.按照name查找pwd
getPasswordByName = "select pwd from t_bd_user where number = '" + number + "'";
sm = conn.createStatement();
rs = sm.executeQuery(getPasswordByName);
// 3.判断pwd是否一致
if (rs != null && rs.next()) {
if (pwd.equals(rs.getString("pwd"))) {
b = true;
}
}
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
dbUtil.closeStatement(sm);
dbUtil.closeConnection(conn);
}
return b;
}
public String getNameByNumber(String number) {
String name = null;
Connection conn = null;
String getPasswordByName = null;
Statement sm = null;
ResultSet rs = null;
DBUtil dbUtil = new DBUtil();
try {
// 1.获取数据库连接
conn = dbUtil.getConn();
// 2.按照name查找pwd
getPasswordByName = "select name from t_bd_user where number = '" + number + "'";
sm = conn.createStatement();
rs = sm.executeQuery(getPasswordByName);
// 3.判断pwd是否一致
if (rs != null && rs.next()) {
name = rs.getString("name");
}
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
dbUtil.closeStatement(sm);
dbUtil.closeConnection(conn);
}
return name;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -