📄 adminuser.java
字号:
package admin.user;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
import zd.bbs.DataBaseConnection;
public class AdminUser
{
private Connection con;
public AdminUser() {
DataBaseConnection dbc = new DataBaseConnection() ;
this.con=dbc.getConnection();
}
//�鿴���е�ע���û�
public Collection getAllUser()throws Exception{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("SELECT * FROM zu ");
Collection ret=new ArrayList();
while(rst.next()){
Note note=new Note();
note.setUser_id(rst.getInt("user_id"));
note.setUsername(rst.getString("username"));
note.setPassword(rst.getString("password"));
note.setSex(rst.getInt("sex"));
note.setTag(rst.getString("tag"));
note.setQq(rst.getString("qq"));
note.setEmail(rst.getString("email"));
note.setHow(rst.getString("how"));
note.setWorks(rst.getString("works"));
note.setPhone(rst.getString("phone"));
note.setQuxian(rst.getInt("quxian"));
ret.add(note);
}
con.close();
return ret;
}
//��id�鿴�û���
public Note getuser(String id)throws Exception{
Statement stmt=con.createStatement();
String sql="select * from zu where user_id="+id+"";
sql=new String(sql.getBytes("ISO8859-1"), "GB2312");
ResultSet rst=stmt.executeQuery(sql);
Note note=null;
while(rst.next()){
note=new Note();
note.setUser_id(rst.getInt("user_id"));
note.setUsername(rst.getString("username"));
note.setQuxian(rst.getInt("quxian"));
}
return note;
}
//�û�Ȩ����
public void UserEdit(int quxian,int user_id)throws Exception{
Statement stmt=con.createStatement();
String sql="update zu set quxian="+quxian+" where user_id="+user_id+"";
stmt.execute(sql);;
stmt.close();
}
//ɾ��ע���û�
public void delUser(String id)throws Exception{
Statement stmt=con.createStatement();
stmt.execute("delete from zu where user_id="+id+"");
stmt.close();
}
//�鿴���еİ���
public Collection getAllBanzhu()throws Exception{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select username from zu where quxian=1");
Collection ret=new ArrayList();
while(rst.next()){
Note note=new Note();
note.setUsername(rst.getString("username"));
ret.add(note);
}
stmt.close();
return ret ;
}
//����
public void addBanZhu(BanzhuFrom banzhuFrom) throws Exception{
String sql="insert into banzhu(banzhu_name,banzhu_bankuai) values(?,?)";
sql=new String(sql.getBytes("ISO8859-1"), "GB2312");
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1,banzhuFrom.getBanzhu_name());
pstmt.setString(2,banzhuFrom.getBanzhu_bankuai());
pstmt.execute();
pstmt.close();
}
//����
//�����û������ģ���ѯ����
public Vector getchaxun(String key)throws Exception{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from zu where username like '%"+key+"%'");
//Collection ret=new ArrayList();
Vector vector = new Vector();
while(rst.next()){
Note note=new Note();
note.setUser_id(rst.getInt("user_id"));
note.setUsername(rst.getString("username"));
note.setPassword(rst.getString("password"));
note.setSex(rst.getInt("sex"));
note.setTag(rst.getString("tag"));
note.setQq(rst.getString("qq"));
note.setEmail(rst.getString("email"));
note.setHow(rst.getString("how"));
note.setWorks(rst.getString("works"));
note.setPhone(rst.getString("phone"));
note.setQuxian(rst.getInt("quxian"));
vector.add(note);
}
con.close();
return vector;
}
//����Ա��½
public boolean checkAdmin(String username,String password) throws Exception{
Statement stmt=con.createStatement();
String sql="select * from zu where username='"+username+"'and password='"+password+"'and quxian=0";
ResultSet rst=stmt.executeQuery(sql);
if (rst.next()) {
return true;
} else {
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -