userop.java
来自「一个JAVA做的博客系统。系统采用JSP + JS + TOMCAT + MYS」· Java 代码 · 共 52 行
JAVA
52 行
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 + =
减小字号Ctrl + -
显示快捷键?