📄 userdao.java
字号:
package com.weipure.struts.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.weipure.struts.form.LogonForm;
import com.weipure.struts.tool.DBConnection;
public class UserDAO {
private DBConnection dbc = new DBConnection();
public boolean isUserExisted(String username, String password) {
String sql = "select * from users where usname='" + username
+ "' and psword='" + password + "'";
ResultSet rs = (ResultSet) dbc.executeQuery(sql);
try {
if (rs.next()) {
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
dbc.close();
return false;
}
// public String verify(String username, String password) {
// String result = null;
// Connection conn = null;
// Statement st = null;
// ResultSet rs = null;
// conn = dbc.getConnection();
// try {
// st = conn.createStatement();
// rs = st.executeQuery("select psword from users where usname='"
// + username + "'");
// if (rs.next()) {
// if (password.equals(rs.getString("psword"))) {
// result = "OK";
// } else {
// result = "PWD";
// }
// } else {
// result = "NOUSER";
// }
// } catch (SQLException e) {
// e.printStackTrace();
// }finally{
// try {
// if(rs!=null)rs.close();
// if(st!=null)st.close();
//
// } catch (SQLException e) {
// e.printStackTrace();
// }
// }
//
// return result;
// }
public String verify(String username, String password) {
String result = null;
String sql = "select psword from users where usname='"
+ username + "'";
ResultSet rs = (ResultSet) dbc.executeQuery(sql);
try {
if (rs.next()) {
if (password.equals(rs.getString("psword"))) {
result = "OK";
} else {
result = "PWD";
}
} else {
result = "NOUSER";
}
} catch (SQLException e) {
e.printStackTrace();
}
dbc.close();
return result;
}
public int register(LogonForm lf) {
int num = 0;
String sql = "insert into users(usname,psword) values('"
+ lf.getUsername()+ "','" + lf.getPassword() +"')";
num = dbc.executeUpdate(sql);
dbc.close();
return num;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -