package com.neusoft.dao;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.neusoft.dao.util.JSH_ConnectionUtil;
import com.neusoft.vo.JSH_Users;
public class JSH_UsersDAO {
//用户注册
public void userRegister(String name,String passwd,String email,String role){
Connection conn=null;
PreparedStatement pstmt=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:oracle","scott","tiger");
String sql="insert into users(id,name,passwd,email,roles)values(seq_users.nextval,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, passwd);
pstmt.setString(3, email);
pstmt.setString(4, role);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(pstmt!=null) pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(conn!=null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
//添加用户
public void userAdd(String name,String passwd,String email){
Connection conn=null;
PreparedStatement pstmt=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:oracle","scott","tiger");
String sql="insert into users(id,name,passwd,email,roles)values(seq_users.nextval,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, passwd);
pstmt.setString(3, email);
pstmt.setString(4, "普通用户");
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(pstmt!=null) pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(conn!=null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
//用户删除
public void delUser(int id){
Connection conn = null;
PreparedStatement pstmt = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:oracle","scott","tiger");
String sql = "delete from users where id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, id);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
JSH_ConnectionUtil.close(conn, pstmt);
}
}
//管理员添加用户
public void updateUser(String name,String passwd,String email,int id) {
Connection conn = null;
PreparedStatement pstmt = null;
try {
String sql = "update users set passwd=? , email=? , name=? where id=? ";
conn= JSH_ConnectionUtil.createConn();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, passwd);
pstmt.setString(2, email);
pstmt.setString(3, name);
pstmt.setInt(4, id);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
JSH_ConnectionUtil.close(conn, pstmt);
}
}
//管理员修改用户
public void adminUpdateUser(String name,String passwd,String email,String roles,int id) {
Connection conn = null;
PreparedStatement pstmt = null;
try {
String sql = "update users set name=? ,passwd=?,email=?,roles=? where id=? ";
conn= JSH_ConnectionUtil.createConn();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, passwd);
pstmt.setString(3, email);
pstmt.setString(4, roles);
pstmt.setInt(5, id);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
JSH_ConnectionUtil.close(conn, pstmt);
}
}
//得到所有用户信息
public List<JSH_Users> getAllUsers(){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
List<JSH_Users> list = new ArrayList<JSH_Users>();
String sql = "select * from users";
try{
conn= JSH_ConnectionUtil.createConn();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
String passwd=rs.getString("passwd");
String email=rs.getString("email");
String role=rs.getString("roles");
JSH_Users user= new JSH_Users();
user.setId(id);
user.setName(name);
user.setPasswd(passwd);
user.setEmail(email);
user.setRoles(role);
list.add(user);
}
}catch(Exception e){
e.printStackTrace();
}finally{
JSH_ConnectionUtil.close(conn, stmt,rs);
}
return list;
}
//根据用户的ID得到用户的信息
public List<JSH_Users> getUserById(int id){
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<JSH_Users> list = new ArrayList<JSH_Users>();
try{
String sql = "select * from users where id=?";
conn= JSH_ConnectionUtil.createConn();
pstmt =conn.prepareStatement(sql);
pstmt.setInt(1, id);
rs = pstmt.executeQuery();
while(rs.next()){
id = rs.getInt("id");
String name = rs.getString("name");
String passwd=rs.getString("passwd");
String email=rs.getString("email");
String role=rs.getString("roles");
JSH_Users user1= new JSH_Users();
user1.setId(id);
user1.setName(name);
user1.setPasswd(passwd);
user1.setEmail(email);
user1.setRoles(role);
list.add(user1);
}
}catch(Exception e){
e.printStackTrace();
}finally{
JSH_ConnectionUtil.close(conn, pstmt,rs);
}
return list;
}
//模糊查询
public List<JSH_Users> getUserByMohu(String name){
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<JSH_Users> list = new ArrayList<JSH_Users>();
try{
String sql = "select * from users where name like ?";
conn= JSH_ConnectionUtil.createConn();
pstmt =conn.prepareStatement(sql);
pstmt.setString(1, "%"+name+"%");
rs = pstmt.executeQuery();
while(rs.next()){
int id = rs.getInt("id");
name = rs.getString("name");
String passwd=rs.getString("passwd");
String email=rs.getString("email");
String role=rs.getString("roles");
JSH_Users user2= new JSH_Users();
user2.setId(id);
user2.setName(name);
user2.setPasswd(passwd);
user2.setEmail(email);
user2.setRoles(role);
list.add(user2);
}
}catch(Exception e){
e.printStackTrace();
}finally{
JSH_ConnectionUtil.close(conn, pstmt,rs);
}
return list;
}
//用户验证
public boolean getJSH_User(String name,String passwd){
boolean result=false;
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
//List<JSH_Users> list = new ArrayList<JSH_Users>();
try{
String sql = "select name,passwd,roles from users";
conn= JSH_ConnectionUtil.createConn();
stmt=conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
if((name.equals(rs.getString("name")))&&(passwd.equals(rs.getString("passwd")))){
result=true;
return result;
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
JSH_ConnectionUtil.close(conn, stmt,rs);
}
return result;
}
//得到用户信息
public List<JSH_Users> getJSH_User1(String name,String passwd){
String email;
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
List<JSH_Users> list=n
没有合适的资源?快使用搜索试试~ 我知道了~
用户管理系统----在oracle下
共12个文件
class:5个
java:5个
classpath:1个
1星 需积分: 10 19 下载量 8 浏览量
2011-04-27
09:36:18
上传
评论 2
收藏 18KB RAR 举报
温馨提示
用java开发,连接oracle数据库,这是一个基础的用java开发的小型用户管理系统
资源推荐
资源详情
资源评论
收起资源包目录
java+oracle+myeclipse用户管理系统.rar (12个子文件)
靳守红
UserManageSys
bin
com
neusoft
dao
util
JSH_ConnectionUtil.class 2KB
JSH_UsersDAO.class 9KB
vo
JSH_Users.class 1KB
neusot
test
JSH_Test.class 577B
DiaoYongMathod.class 8KB
src
com
neusoft
dao
JSH_UsersDAO.java 9KB
util
JSH_ConnectionUtil.java 2KB
vo
JSH_Users.java 691B
neusot
test
DiaoYongMathod.java 9KB
JSH_Test.java 260B
.project 389B
.classpath 374B
共 12 条
- 1
资源评论
- vnp_wzap2013-12-23没看出来怎么用,不是vs运行程序,郁闷
飞鸿123
- 粉丝: 0
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功