📄 webuserdao.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.WebUserObject;
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: WebUserDao.java,v 1.1 2004/06/14 09:22:04 wengjl Exp $
*/
public class WebUserDao {
//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(WebUserDao.class);
StringBuffer sql = new StringBuffer("select * from webuser where username=? 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 static int addWebuser(WebUserObject info){//增加数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0;
try {
con = ConnectionManager.getInstance().getConnection(WebUserDao.class);
String sql = " INSERT INTO webuser ( username,password,realname,mobile,tel,address,email,ic,devicetype,usertype ) VALUES ( ?,?, ?, ? , ?, ?, ?,?,?,?) ";
pstmt = con.prepareStatement(sql.toString());//往数据库增加数据
if (info.getUsername() == null){
pstmt.setNull(1, Types.VARCHAR);
}else{
pstmt.setString(1, info.getUsername());
}
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.getAddress()==null){
pstmt.setNull(6, Types.VARCHAR);
}else{
pstmt.setString(6, info.getAddress());
}
if (info.getEmail()==null){
pstmt.setNull(7, Types.VARCHAR);
}else{
pstmt.setString(7, info.getEmail());
}
if (info.getIc()==null){
pstmt.setNull(8, Types.VARCHAR);
}else{
pstmt.setString(8, info.getIc());
}
if (info.getDevicetype()==null){
pstmt.setNull(9, Types.VARCHAR);
}else{
pstmt.setString(9, info.getDevicetype());
}
if (info.getUsertype()==null){
pstmt.setNull(10, Types.VARCHAR);
}else{
pstmt.setString(10, info.getUsertype());
}
System.out.println("qian");
rs = pstmt.executeUpdate();
System.out.println("hou" + rs + " " + sql.toString());
}
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 WebUserObject[] getAllSysuser(WebUserObject info) throws SQLException {//查询所有数据
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList list = new ArrayList();
try{
con = ConnectionManager.getInstance().getConnection(WebUserDao.class);
StringBuffer sql = new StringBuffer("select a.username,a.password,a.realname,a.mobile,a.tel,");
sql.append( "a.address,a.email,a.ic,a.devicetype,a.usertype");
sql.append( " from webuser a");
sql.append( " where 1=1 ");
if (info!=null && info.getUsername()!=null){
sql.append(" and a.username = '" + info.getUsername()+ "'");
}
logger.debug(sql.toString() + " sql");
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeQuery();
while (rs.next()){
WebUserObject model = new WebUserObject();
String id = rs.getString("username");
if (!rs.wasNull()) model.setUsername(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 address = rs.getString("address");
if (!rs.wasNull()) model.setAddress(address);
String email = rs.getString("email");
if (!rs.wasNull()) model.setEmail(email);
String ic = rs.getString("ic");
if (!rs.wasNull()) model.setIc(ic);
String devicetype = rs.getString("devicetype");
if (!rs.wasNull()) model.setDevicetype(devicetype);
String usertype = rs.getString("usertype");
if (!rs.wasNull()) model.setUsertype(usertype);
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 (WebUserObject[])list.toArray(new WebUserObject[list.size()]);
}
public int deleteWebuser(WebUserObject infovalue) throws SQLException {//删除数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(WebUserDao.class);
StringBuffer sql = new StringBuffer("delete from webuser where 1=1 ");
sql.append( "and admin.username = '" + infovalue.getUsername() + "'");
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(WebUserObject infovalue) throws SQLException {//修改数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(WebUserDao.class);
StringBuffer sql = new StringBuffer("update webuser set ");
if (infovalue.getUsername()!=null){
if (infovalue.getUsername().equals("@_@")){
sql.append( " webuser.username = null, ");
}else{
sql.append( " webuser.username = '" + infovalue.getUsername()+ "',");
}
}
if (infovalue.getPassWord()!=null){
if (infovalue.getPassWord().equals("@_@")){
sql.append( " webuser.password = null, ");
}else{
sql.append( " webuser.password = '" + infovalue.getPassWord() + "',");
}
}
if (infovalue.getRealName()!=null){
if (infovalue.getRealName().equals("@_@")){
sql.append( " webuser.realname = null, ");
}else{
sql.append( " webuser.realname = '" + infovalue.getRealName() + "',");
}
}
if (infovalue.getTel()!=null){
if (infovalue.getTel().equals("@_@")){
sql.append( " webuser.tel = null, ");
}else{
sql.append( " webuser.tel = '" + infovalue.getTel() + "',");
}
}
if (infovalue.getAddress()!=null){
if (infovalue.getAddress().equals("@_@")){
sql.append( " webuser.address = null, ");
}else{
sql.append( " webuser.address = '" + infovalue.getAddress() + "',");
}
}
if (infovalue.getEmail()!=null){
if (infovalue.getEmail().equals("@_@")){
sql.append( " webuser.email = null, ");
}else{
sql.append( " webuser.email = '" + infovalue.getEmail() + "',");
}
}
if (infovalue.getIc()!=null){
if (infovalue.getIc().equals("@_@")){
sql.append( " webuser.ic = null, ");
}else{
sql.append( " webuser.ic = '" + infovalue.getIc() + "',");
}
}
if (infovalue.getDevicetype()!=null){
if (infovalue.getDevicetype().equals("@_@")){
sql.append( " webuser.devicetype = null, ");
}else{
sql.append( " webuser.devicetype = '" + infovalue.getDevicetype() + "',");
}
}
if (infovalue.getUsertype()!=null){
if (infovalue.getUsertype().equals("@_@")){
sql.append( " webuser.usertype = null, ");
}else{
sql.append( " webuser.usertype = '" + infovalue.getUsertype() + "',");
}
}
sql.setLength(sql.length()-1);
sql.append( " where 1=1");
if (infovalue.getUsername()!=null){
sql.append(" and webuser.username = '" + infovalue.getUsername()+ "'");
}
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(WebUserDao.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -