📄 sysuserdao.java
字号:
package com.gctech.sms.dao;
import java.util.Collection;
import java.util.Map;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import org.apache.log4j.Logger;
import com.gctech.sms.util.ConnectionManager;
import java.sql.PreparedStatement;
import java.sql.*;
import com.gctech.sms.vo.SysUserObject;
import java.util.ArrayList;
/**
* <p>Title: SP管理模块</p>
* <p>Description: 负责增、删除、修改Sp数据</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: gctech</p>
* @author wengjl
* @version $Id: SysUserDao.java,v 1.4 2004/05/09 05:13:52 wengjl Exp $
*/
public class SysUserDao {
//public SpInfoDao() {
//}
public static boolean isTrue(String name, String password) throws SQLException {//查询所有数据
logger.debug(":"+name +":"+password+":");
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean rz = false;
try{
con = ConnectionManager.getInstance().getConnection(SysUserDao.class);
StringBuffer sql = new StringBuffer("select * from admin where loginid=? and password=?");
logger.debug(sql.toString());
pstmt = con.prepareStatement(sql.toString());
pstmt.setString(1,name);
pstmt.setString(2,password);
rs = pstmt.executeQuery();
if (rs.next()){
logger.debug("truetrue");
rz = true;
}
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( rs != null ){
try {
rs.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
logger.debug(rz + " ");
return rz;
}
public int updateSysuser(String userid,String pswd) throws SQLException {//更新数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(SysUserDao.class);
StringBuffer sql = new StringBuffer("update admin set ");
sql.append( " admin.password = '" + pswd+ "',");
sql.setLength(sql.length()-1);
sql.append( " where 1=1");
if (userid!=null){
sql.append(" and admin.loginid = '" + userid + "'");
}
pstmt = con.prepareStatement(sql.toString());
logger.debug(sql.toString() + " rs返回");
rs = pstmt.executeUpdate();
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
return rs;
}
public static int addSysuser(SysUserObject info){//增加数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0;
try {
con = ConnectionManager.getInstance().getConnection(SysUserDao.class);
String sql = " INSERT INTO admin ( loginid,password,realname,mobile,tel,email ) VALUES ( ?, ?, ? , ?, ?, ?) ";
pstmt = con.prepareStatement(sql.toString());//往数据库增加数据
if (info.getLongInID() == null){
pstmt.setNull(1, Types.VARCHAR);
}else{
pstmt.setString(1, info.getLongInID());
}
if (info.getPassWord()==null){
pstmt.setNull(2, Types.VARCHAR);
}else{
pstmt.setString(2, info.getPassWord());
}
if (info.getRealName()==null){
pstmt.setNull(3, Types.VARCHAR);
}else{
pstmt.setString(3, info.getRealName());
}
if (info.getMobile()==null){
pstmt.setNull(4, Types.VARCHAR);
}else{
pstmt.setString(4, info.getMobile());
}
if (info.getTel()==null){
pstmt.setNull(5, Types.VARCHAR);
}else{
pstmt.setString(5, info.getTel());
}
if (info.getEmail()==null){
pstmt.setNull(6, Types.VARCHAR);
}else{
pstmt.setString(6, info.getEmail());
}
rs = pstmt.executeUpdate();
}
catch (Throwable ex) {
logger.error(ex, ex);
}finally{
if ( pstmt != null ){
try {
pstmt.close();
}
catch (SQLException ex1) {
logger.error(ex1, ex1);
}
}
if ( con != null ){
try {
con.close();
}
catch (SQLException ex1) {
logger.error(ex1, ex1);
}
}
}
return rs;
}
public static SysUserObject[] getAllSysuser(SysUserObject info) throws SQLException {//查询所有数据
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList list = new ArrayList();
try{
con = ConnectionManager.getInstance().getConnection(SysUserDao.class);
StringBuffer sql = new StringBuffer("select a.loginid,a.password,a.realname,a.mobile,a.tel,");
sql.append( "a.email");
sql.append( " from admin a");
sql.append( " where 1=1 ");
if (info!=null && info.getLongInID()!=null){
sql.append(" and a.loginid = '" + info.getLongInID()+ "'");
}
logger.debug(sql.toString() + " sql");
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeQuery();
while (rs.next()){
SysUserObject model = new SysUserObject();
String id = rs.getString("loginid");
if (!rs.wasNull()) model.setLongInID(id);
String password = rs.getString("password");
if (!rs.wasNull()) model.setPassWord(password);
String realname = rs.getString("realname");
if (!rs.wasNull()) model.setRealName(realname);
String mobile = rs.getString("mobile");
if (!rs.wasNull()) model.setMobile(mobile);
String tel = rs.getString("tel");
if (!rs.wasNull()) model.setTel(tel);
String email = rs.getString("email");
if (!rs.wasNull()) model.setEmail(email);
list.add(model);
}
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( rs != null ){
try {
rs.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
return (SysUserObject[])list.toArray(new SysUserObject[list.size()]);
}
public int deleteSysuser(SysUserObject infovalue) throws SQLException {//删除数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(SysUserDao.class);
StringBuffer sql = new StringBuffer("delete from admin where 1=1 ");
sql.append( "and admin.loginid = '" + infovalue.getLongInID() + "'");
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeUpdate();
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
return rs;
}
public int updateUser(SysUserObject infovalue) throws SQLException {//修改数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(SysUserDao.class);
StringBuffer sql = new StringBuffer("update admin set ");
if (infovalue.getLongInID()!=null){
if (infovalue.getLongInID().equals("@_@")){
sql.append( " admin.loginid = null, ");
}else{
sql.append( " admin.loginid = '" + infovalue.getLongInID()+ "',");
}
}
if (infovalue.getPassWord()!=null){
if (infovalue.getPassWord().equals("@_@")){
sql.append( " admin.password = null, ");
}else{
sql.append( " admin.password = '" + infovalue.getPassWord() + "',");
}
}
if (infovalue.getRealName()!=null){
if (infovalue.getRealName().equals("@_@")){
sql.append( " admin.realname = null, ");
}else{
sql.append( " admin.realname = '" + infovalue.getRealName() + "',");
}
}
if (infovalue.getTel()!=null){
if (infovalue.getTel().equals("@_@")){
sql.append( " admin.tel = null, ");
}else{
sql.append( " admin.tel = '" + infovalue.getTel() + "',");
}
}
if (infovalue.getEmail()!=null){
if (infovalue.getEmail().equals("@_@")){
sql.append( " admin.email = null, ");
}else{
sql.append( " admin.email = '" + infovalue.getEmail() + "',");
}
}
sql.setLength(sql.length()-1);
sql.append( " where 1=1");
if (infovalue.getLongInID()!=null){
sql.append(" and admin.loginid = '" + infovalue.getLongInID()+ "'");
}
logger.debug(sql.toString() + " update");
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeUpdate();
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
return rs;
}
static final Logger logger = Logger.getLogger(SysUserDao.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -