📄 op_user.java~81~
字号:
db.finalize();
return true;
}
catch (SQLException e)
{
System.out.print(e.getMessage());
return false;
}
}
//修改用户
public boolean update(HttpServletRequest req) throws Exception
{
if (getRequest(req))
{
sqlStr = "update shop_user set ";
sqlStr = sqlStr + "username = '" + dataFormat.toSql(user.getUserName()) + "',";
sqlStr = sqlStr + "password = '" + dataFormat.toSql(user.getPassWord()) + "',";
sqlStr = sqlStr + "Names = '" + dataFormat.toSql(user.getNames()) + "',";
sqlStr = sqlStr + "sex = '" + dataFormat.toSql(user.getSex()) + "',";
sqlStr = sqlStr + "address = '" + dataFormat.toSql(user.getAddress()) + "',";
sqlStr = sqlStr + "phone = '" + dataFormat.toSql(user.getPhone()) + "',";
sqlStr = sqlStr + "post = '" + dataFormat.toSql(user.getPost()) + "',";
sqlStr = sqlStr + "Email = '" + dataFormat.toSql(user.getEmail()) + "' ";
sqlStr = sqlStr + " WHERE id = '" + user.getId() + "'";
try
{
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
db.stmt.execute(sqlStr);
db.finalize();
return true;
} catch (SQLException e)
{
return false;
}
}
else
{
return false;
}
}
//删除用户
public boolean delete( long aid ) throws Exception
{
sqlStr = "DELETE FROM shop_user WHERE id = " + aid ;
try
{
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
db.stmt.execute(sqlStr);
db.finalize();
return true;
}
catch (SQLException e)
{
System.out.println(e);
return false;
}
}
//查询指定id的用户,用于支持页面的查看详细资料请求
public boolean getUserinfo(long newid ) throws Exception
{
try
{
sqlStr = "SELECT id, username, password, names, sex, ";
sqlStr += " address, Phone, post, email, regtime, RegIpaddress, userpoint ";
sqlStr += " FROM shop_user ";
sqlStr += " WHERE Id = " + newid ;
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
rs = db.stmt.executeQuery(sqlStr);
if( !rs.next() )
{
userlist = new Vector();
do
{
user.setId(rs.getLong("id"));
System.out.print(rs.getLong("id"));
user.setUserName(rs.getString("username"));
user.setPassWord(rs.getString("password"));
user.setNames(rs.getString("names"));
user.setSex(rs.getString("sex"));
user.setAddress(rs.getString("address"));
user.setPhone(rs.getString("Phone"));
user.setPost(rs.getString("post"));
user.setEmail(rs.getString("email"));
user.setRegTime(rs.getString("regtime"));
user.setRegIpAddress(rs.getString("RegIpaddress"));
user.setUserPoint(rs.getInt("userpoint"));
userlist.addElement(user);
}while (rs.next());
rs.close();
db.finalize();
return true;
}
catch (Exception e)
{
System.out.print(e.getMessage());
return false;
}
}
//修改用户积分
public boolean updateUserPoint(String userid,int num)
{
String point=num+"";
String sql="EXECUTE updateUserPoint "+userid+","+point;
//String sql="update shop_user set userpoint=userpoint +"+num+" WHERE id='"+userid+"'";
try
{
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
System.out.println(sql);
db.stmt.execute(sql);
db.finalize();
return true;
}
catch (SQLException e)
{
System.out.println(e.toString());
return false;
}
}
public int getUserPoint(String userid)
{
String sql="SELECT userpoint FROM shop_user WHERE id='"+userid+"'";
try
{
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
rs = db.stmt.executeQuery(sql);
if(rs.next())
{
int iUserPoint = rs.getInt("userpoint");
rs.close();
db.finalize();
return iUserPoint;
}
else return 0;
}
catch (SQLException e)
{
return 0;
}
}
public float getUserRate(String userid)
{
int userPoint=this.getUserPoint(userid);
int lerver=userPoint/100;
switch (lerver)
{
case 0:return 1.0f;
case 1:return 0.95f;
case 2:return 0.90f;
case 3:return 0.85f;
case 4:return 0.80f;
case 5:return 0.75f;
default:return 0.75f;
}
}
public String getGbk( String str)
{
try
{
return new String(str.getBytes("ISO8859-1"));
}
catch (Exception e)
{
return str;
}
}
public int getPage() //显示的页码
{
return page;
}
public void setPage(int newpage)
{
page = newpage;
}
public int getPageSize() //每页显示的图书数
{
return pageSize;
}
public void setPageSize(int newpsize)
{
pageSize = newpsize;
}
public int getPageCount() //页面总数
{
return pageCount;
}
public void setPageCount(int newpcount)
{
pageCount = newpcount;
}
public long getRecordCount()
{
return recordCount;
}
public void setRecordCount(long newrcount)
{
recordCount= newrcount;
}
public String getMessage()
{
return message;
}
public void setMessage(String msg)
{
message = msg;
}
public void setUserid(long uid)
{
userid = uid;
}
public long getUserid()
{
return userid;
}
public void setUserName(String uName)
{
username = uName;
}
public String getUserName()
{
return username;
}
public Vector getUserlist()
{
return userlist;
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -