package com.dao;
import java.sql.*;
import java.util.Collection;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import com.core.Database;
import com.core.FinalConstants;
import com.core.ParamUtils;
import com.model.User;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: MR</p>
* @author BWM
* @version 1.0
*/
public class Dbuser extends User {
private User u = new User();
//不使初始化select
public Dbuser(){}
//使用数据库始化update
public Dbuser(String sql) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = Database.getConnection();
ps = con.prepareStatement(FinalConstants.SELECT_USER+sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = ps.executeQuery();
if (rs.next()) {
u.setUid(ParamUtils.getSqlString(rs.getString("uid")));
u.setPassword(ParamUtils.getSqlString(rs.getString("password")));
u.setName(ParamUtils.getSqlString(rs.getString("name")));
u.setRegqu(ParamUtils.getSqlString(rs.getString("regqu")));
u.setReganswer(ParamUtils.getSqlString(rs.getString("reganswer")));
u.setIid(ParamUtils.getSqlString(rs.getString("iid")));
u.setSex(rs.getInt("sex"));
u.setAge(rs.getInt("age"));
u.setTel(ParamUtils.getSqlString(rs.getString("tel")));
u.setEmail(ParamUtils.getSqlString(rs.getString("email")));
u.setQq(ParamUtils.getSqlString(rs.getString("qq")));
u.setRegtime(ParamUtils.getSqlString(rs.getString("regtime")));
u.setAddress(ParamUtils.getSqlString(rs.getString("address")));
u.setHttp(ParamUtils.getSqlString(rs.getString("http")));
u.setStatus(rs.getInt("status"));
u.setState(rs.getInt("state"));
u.setResume(ParamUtils.getSqlString(rs.getString("resume")));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
System.out.println(ps+" Dbuser(String sql) "+u.getUid());
try {
if (ps != null) {
ps.close();
ps = null;
}
} catch (SQLException e) {
ps = null;
}
try {
if (con != null) {
con.close();
con = null;
}
} catch (SQLException e) {
con = null;
}
}
}
//使用内建对像初始化insert
public Dbuser(HttpServletRequest request) {
u.setUid(ParamUtils.getRequestString(request, "uid"));
u.setPassword(ParamUtils.getRequestString(request, "password"));
u.setName(ParamUtils.getRequestString(request, "name"));
u.setRegqu(ParamUtils.getRequestString(request, "regqu"));
u.setReganswer(ParamUtils.getRequestString(request, "reganswer"));
u.setSex(ParamUtils.getIntParameter(request, "sex"));
u.setAge(ParamUtils.getIntParameter(request, "age"));
u.setIid(ParamUtils.getRequestString(request, "iid"));
u.setTel(ParamUtils.getRequestString(request, "tel"));
u.setEmail(ParamUtils.getRequestString(request, "email"));
u.setQq(ParamUtils.getRequestString(request, "qq"));
u.setAddress(ParamUtils.getRequestString(request, "address"));
u.setHttp(ParamUtils.getRequestString(request, "http"));
u.setStatus(ParamUtils.getIntParameter(request, "status"));
u.setState(ParamUtils.getIntParameter(request, "state"));
u.setResume(ParamUtils.getRequestString(request, "resume"));
}
//注册时间插入系统时间
public boolean Insert() {
boolean b = false;
Connection con = null;
PreparedStatement ps = null;
try {
con = Database.getConnection();
ps = con.prepareStatement(FinalConstants.INSERT_USER);
System.out.println("Dbuser.java中:"+FinalConstants.INSERT_USER+"结束");
ps.setString(1, u.getUid());
ps.setString(2, u.getPassword());
ps.setString(3, u.getName());
ps.setString(4, u.getRegqu());
ps.setString(5, u.getReganswer());
ps.setString(6, u.getIid());
ps.setInt(7, u.getSex());
ps.setInt(8, u.getAge());
ps.setString(9, u.getTel());
ps.setString(10, u.getEmail());
ps.setString(11, u.getQq());
ps.setString(12, u.getAddress());
ps.setString(13, u.getHttp());
ps.setInt(14, u.getStatus());
ps.setInt(15, u.getState());
ps.setString(16, u.getResume());
if (ps.executeUpdate() > 0) {
b = true;
} else {
b = false;
}
} catch (SQLException e) {
b = false;
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
System.out.println(ps+" Dbuser.Insert()");
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
ps = null;
}
try {
if (con != null) {
con.close();
}
} catch (SQLException e) {
con = null;
}
}
return b;
}
private boolean Update() {
boolean b = false;
Connection con = null;
PreparedStatement ps = null;
try {
con = Database.getConnection();
ps = con.prepareStatement(FinalConstants.UPDATE_USER);
ps.setString(1, u.getPassword());
ps.setString(2, u.getName());
ps.setString(3, u.getIid());
ps.setInt(4, u.getSex());
ps.setInt(5, u.getAge());
ps.setString(6, u.getTel());
ps.setString(7, u.getEmail());
ps.setString(8, u.getQq());
ps.setString(9, u.getAddress());
ps.setString(10, u.getHttp());
ps.setInt(11, u.getStatus());
ps.setInt(12, u.getState());
ps.setString(13, u.getResume());
ps.setString(14, u.getUid());
if (ps.executeUpdate() > 0) {
b = true;
} else {
b = false;
}
} catch (SQLException e) {
b = false;
e.printStackTrace();
} finally {
System.out.println(ps+" Dbuser.Update() ");
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
ps = null;
}
try {
if (con != null) {
con.close();
}
} catch (SQLException e) {
con = null;
}
}
return b;
}
private boolean Update_m() {
boolean b = false;
Connection con = null;
PreparedStatement ps = null;
try {
con = Database.getConnection();
ps = con.prepareStatement(FinalConstants.UPDATE_USER_M);
ps.setInt(1, u.getStatus());
ps.setInt(2, u.getState());
ps.setString(3, u.getUid());
if (ps.executeUpdate() > 0) {
b = true;
} else {
b = false;
}
} catch (SQLException e) {
梦回阑珊
- 粉丝: 5626
- 资源: 1717
最新资源
- floyd算法求最小距离代码
- 电动汽车充放电最优调度20 研究了EV充电和放电的调度优化问题 我们首先制定全局调度优化问题,其中优化充电功率以最小化所有在白天执行充电和放电的EV的总成本 全球最佳解决方案提供全球最小的总成本
- 基于51单片机的智能温控风扇基于51单片机的智能温控电扇仿真系统, 功能:获取当前温度,调节档位,并用数模转器调节风扇转速
- 基于STM32H750芯片和SOEM的EtherCAT主站源码 提供配套CUBE工程和 SOEM协议栈使用1.3.1版本 可配套如图所示开发板使用 支持DC同步 可配合汇川IS620N、三洋R
- 综合能源系统优化程序,冷热电系统,考虑温度压力,比体积,熵和焓,通过遗传算法求解
- python-workspace.zip.002
- 考虑电动汽车的微网优化,给出微电网各组成部分的个体模型,并采用粒子群优化算法进行经济调度 仿真结果表明,在微网中加入V2G方法的BEV可以提高聚合者的利润,提高系统的可靠性和稳定性
- 本地文件查重管理工具EasyFileCount v3.0.3.8,支持查找大/重复文件+自动分类筛选
- 综合能源系统优化,冷电系统优化,考虑燃气轮机,空调等设备,建立最优经济调度模型,通过粒子群算法求解
- 分布式电源选址定容 软件:Matlab 介绍:在改进的IEEE33节点系统中分布式电源选择最佳接入点和接入容量,以网损和电压越限惩罚为目标进行粒子群优化,能得出最佳接入点和接入容量,接入前后电
- 关键词:无功优化 粒子群算法 主动配电网 IEEE33节点 基于粒子群的含分布式电源的主动配电网电压-有功-无功优化 软件:MATLAB 介绍:考虑24小时主动配电网有功、无功、电压越限
- 5节点系统电力市场出清:输电阻塞;机组、节点边际电目标函数为发电成本最小 运用matlab中的linprog()函数实现此程序,并附赠CPLEX求解5节点系统目标函数为购电成本最小的潮流计算程序
- python-workspace.zip.003
- 模型预测电流控制,双矢量(有效电压矢量和零矢量占空比分配) 包含解释~
- 营养学计算器PHP源码.zip
- LADRC线性自抗扰,三阶ESO状态扩张观测器,boost升压电路,双闭环控制,双LADRC控制,电压外环采用LADRC线性自抗扰控制(ESO扩张状态观测器采用三阶,自己搭建),电流内环同样采用LAD
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈