📄 userop.java
字号:
package common;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class UserOp
{
public static User getUser(String username) throws SQLException
{
String search = "select password, question, answer"
+ ", popedom from user where username = ?";
ResultSet rs = null;
PreparedStatement PS = null;
User user = null;
PS = DS.getDs().getConnection().prepareStatement(search);
PS.setString(1, username);
rs = PS.executeQuery();
if(rs.next())
user = new User(username, rs.getString(1),
rs.getString(2), rs.getString(3), rs.getInt(4));
return user;
}
public static User getUser(String username, String password) throws SQLException
{
String search = "select question, answer, popedom"
+ " from user where username = ? and password = ?";
ResultSet rs = null;
PreparedStatement PS = null;
User user = null;
PS = DS.getDs().getConnection().prepareStatement(search);
PS.setString(1, username);
PS.setString(2, password);
rs = PS.executeQuery();
if(rs.next())
user = new User(username, password, rs.getString(1),
rs.getString(2), rs.getInt(3));
return user;
}
public static boolean isExists(String username) throws SQLException
{
String search = "select count(*) from user where username = ?";
ResultSet rs = null;
PreparedStatement PS = null;
PS = DS.getDs().getConnection().prepareStatement(search);
PS.setString(1, username);
rs = PS.executeQuery();
rs.next();
if(rs.getInt(1) == 0) return false;
else return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -