package com.jkx.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.jkx.po.User;
import com.jkx.util.DBconn;
public class UserDao {
//데절친駕
public UserDao(){
}
public static UserDao userdao=new UserDao();
public static UserDao getIntance()
{
return userdao;
}
public boolean saveUser(User user) throws SQLException
{
boolean flag=false;
Connection conn=null;
//Statement st=null;
PreparedStatement ps=null;
try {
conn=DBconn.getConnetctio();
String sql ="insert into user(username,password,flag) values(?,?,?)";
ps=conn.prepareStatement(sql);
ps.setString(1, user.getUsername());
ps.setString(2, user.getPassword());
ps.setString(3, user.getFlag());
//st=conn.createStatement();
int rows=ps.executeUpdate();
if(rows>0)
{
flag=true;
}
System.out.println(sql);
}
finally
{
DBconn.Psclose(ps,conn);
}
return flag;
}
public boolean deleteUserById(int userid) throws SQLException
{
boolean boo=false;
Connection conn=null;
//Statement st=null;
PreparedStatement ps=null;
try {
conn=DBconn.getConnetctio();
String sql ="delete from user where userid=?";
//st=conn.createStatement();
ps=conn.prepareStatement(sql);
ps.setInt(1, userid);
//int rows=st.executeUpdate(sql);
int rows=ps.executeUpdate();
if(rows>0)
{
boo=true;
}
}
finally
{
DBconn.Psclose(ps,conn);
}
return boo;
}
public boolean updateUserById(Map<String, Object> map) throws SQLException
{
boolean boo=false;
Connection conn=null;
Statement st=null;
try {
conn=DBconn.getConnetctio();
String sql ="update user set username='"+(String)map.get("username")+"' where userid="+(Integer)map.get("userid");
st=conn.createStatement();
int rows=st.executeUpdate(sql);
if(rows>0)
{
boo=true;
}
}
finally
{
DBconn.close(st,conn);
}
return boo;
}
public User getUserByusernameAndPasswoed(String name,String pass)
{
User user=null;
Connection conn=null;
PreparedStatement ps=null;
conn=DBconn.getConnetctio();
ResultSet rs=null;
String sql ="select * from user where username=? and password=?";
try {
ps=conn.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, pass);
rs=ps.executeQuery();
if(rs.next())
{
user=new User();
user.setUserid(rs.getInt("userid"));
user.setUsername(rs.getString("username"));
user.setPassword(rs.getString("password"));
user.setFlag(rs.getString("flag"));
user.setSex(rs.getInt("sex"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DBconn.Rsclose(rs,ps, conn);
}
return user;
}
public List<User> getUserList()
{
List<User> userlist=new ArrayList<User>();
Connection conn=null;
PreparedStatement ps=null;
conn=DBconn.getConnetctio();
ResultSet rs=null;
String sql ="select * from user";
try {
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next())
{
User user=new User();
user.setUserid(rs.getInt("userid"));
user.setUsername(rs.getString("username"));
user.setPassword(rs.getString("password"));
user.setFlag(rs.getString("flag"));
user.setSex(rs.getInt("sex"));
userlist.add(user);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DBconn.Rsclose(rs,ps, conn);
}
return userlist;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
DBconn.zip (79个子文件)
DBconn
.project 2KB
.mymetadata 291B
.svn
tmp
props
prop-base
text-base
props
all-wcprops 356B
entries 682B
prop-base
text-base
.project.svn-base 1KB
.mymetadata.svn-base 291B
.classpath.svn-base 607B
src
.svn
tmp
props
prop-base
text-base
props
all-wcprops 77B
entries 217B
prop-base
text-base
com
.svn
tmp
props
prop-base
text-base
props
all-wcprops 81B
entries 221B
prop-base
text-base
jkx
.svn
tmp
props
prop-base
text-base
props
all-wcprops 85B
entries 245B
prop-base
text-base
dao
UserDao.java 4KB
.svn
tmp
props
prop-base
text-base
props
all-wcprops 323B
entries 511B
prop-base
text-base
PersonDao.java.svn-base 2KB
UserDao.java.svn-base 3KB
PersonDao.java 2KB
web
servlet
FirstServlet.java 2KB
LoginServlet.java 2KB
util
DBconn.java 3KB
test
PersonDaoTest.java 888B
.svn
tmp
props
prop-base
text-base
props
all-wcprops 342B
entries 519B
prop-base
text-base
UserDaoTest.java.svn-base 1KB
PersonDaoTest.java.svn-base 888B
UserDaoTest.java 2KB
po
User.java 761B
.svn
tmp
props
prop-base
text-base
props
all-wcprops 308B
entries 502B
prop-base
text-base
User.java.svn-base 761B
Person.java.svn-base 680B
Person.java 680B
jdbc.properties 107B
WebRoot
WEB-INF
.svn
tmp
props
prop-base
text-base
props
all-wcprops 194B
entries 382B
prop-base
text-base
web.xml.svn-base 404B
classes
.svn
tmp
props
prop-base
text-base
props
all-wcprops 97B
entries 227B
prop-base
text-base
com
jkx
dao
PersonDao.class 3KB
UserDao.class 5KB
web
servlet
LoginServlet.class 2KB
FirstServlet.class 2KB
util
DBconn.class 3KB
test
UserDaoTest.class 3KB
PersonDaoTest.class 2KB
po
User.class 1KB
Person.class 1KB
jdbc.properties 107B
lib
mysql-connector-java-5.1.27.jar 852KB
.svn
tmp
props
prop-base
text-base
props
all-wcprops 250B
entries 398B
prop-base
mysql-connector-java-5.1.27.jar.svn-base 53B
text-base
mysql-connector-java-5.1.27.jar.svn-base 852KB
web.xml 830B
.svn
tmp
props
prop-base
text-base
props
all-wcprops 182B
entries 381B
prop-base
text-base
index.jsp.svn-base 834B
index.jsp 3KB
META-INF
MANIFEST.MF 36B
.svn
tmp
props
prop-base
text-base
props
all-wcprops 204B
entries 362B
prop-base
text-base
MANIFEST.MF.svn-base 36B
.myeclipse
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
.svn
tmp
props
prop-base
text-base
props
all-wcprops 981B
entries 1KB
prop-base
text-base
org.eclipse.wst.jsdt.ui.superType.container.svn-base 49B
org.eclipse.wst.common.component.svn-base 456B
org.eclipse.wst.common.project.facet.core.xml.svn-base 252B
org.eclipse.jdt.core.prefs.svn-base 364B
.jsdtscope.svn-base 500B
org.eclipse.wst.jsdt.ui.superType.name.svn-base 6B
org.eclipse.jdt.core.prefs 364B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 456B
.jsdtscope 500B
.classpath 607B
共 79 条
- 1
资源评论
别不说话
- 粉丝: 15
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- IOException(解决方案).md
- ImportError.md
- NSInvalidObjectException如何解决.md
- DSP信号采集处理与控制系统设计总结实验报告(卷积 FFT FIR 滤波算法源码)
- 毕设和企业适用springboot智慧办公平台类及城市智能运营平台源码+论文+视频.zip
- 电力系统静态稳定性仿真Matlab编程 simulink仿真 1.用Matlab编程,把转子运动方程(摇摆方程)在运行点处线性化,采用小信号分析法,对线性化之后状态方程的系数矩阵求解特征值,根轨迹,通
- EXCEL使用宏实现筛选重复项并对该行进行填充内容的操作
- 锂电池主动均衡simulink仿真 四节电池 基于buckboost(升降压)拓扑 (还有传统电感均衡+开关电容均衡+双向反激均衡+双层准谐振均衡+环形均衡器+cuk+耦合电感)被动均衡电阻式均衡
- Python实现递归遍历Windows文件系统:os模块与pathlib模块的比较
- 操作系统:核心功能、发展历程及未来趋势
- 基于蚁群算法解决的旅行商问题(Vrp)
- b站上是教程,这个是狂暴机器人源码
- 小蜗牛-STC3F.zip
- untitled.fig
- 1834_129789020.html
- 堆排序算法解析:原理、实现与优缺点
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功