📄 dao.java
字号:
package modle_dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
public class Dao {
// 注册
public static boolean Registration_DAO(String username, String userpass)
throws SQLException {
MysqlDb db = new MysqlDb();
int user_id = 0;
int update = 0;
String select_id_sql = "SELECT MAX(user_id) AS user_id FROM NEWS_USER";
try {
ResultSet rs = db.ExcecuteQuery(select_id_sql);
if (rs.next()) {
user_id = rs.getInt("user_id");
user_id += 1;
}
} catch (SQLException e) {
e.printStackTrace();
e.getNextException();
}
String user_update_sql = "INSERT INTO NEWS_USER VALUES('" + user_id
+ "','" + username + "','" + userpass + "')";
System.out.println(user_update_sql);
update = db.ExcecuteUpdate(user_update_sql);
if (update == 1) {
return true;
}
return false;
}
// 登陆
public static boolean Loginaction_User_Select_DAO(String user_name,
String user_pass) {
MysqlDb db = new MysqlDb();
String user_name_sql;
boolean user_name_boolean;
String user_select = "SELECT USER_NAME FROM NEWS_USER WHERE USER_NAME='"
+ user_name + "' AND USER_PASS='" + user_pass + "'";
try {
ResultSet rs = db.ExcecuteQuery(user_select);
if (rs.next()) {
user_name_sql = rs.getString("USER_NAME");
System.out.println("user_name:" + user_name_sql);
if (user_name_sql.equals("") || user_name_sql == null) {
return false;
}
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -