package com.ljf.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.ljf.model.House;
import com.ljf.model.Users;
public class HouseDao extends BaseDao {
/**
* 增加一条租房信息
*
* @param info
* @return
*/
public boolean saveHourse(House info) {
boolean isflat = false;
String sql = "insert into t_house(p_id,h_title,h_qx,h_jd,h_shi,h_ting,h_type,h_price,h_per,h_tel,h_remark) "
+ "values(?,?,?,?,?,?,?,?,?,?,?)";
Connection conn = this.getConn();
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, info.getP_id());
ps.setString(2, info.getH_title());
ps.setString(3, info.getH_qx());
ps.setString(4, info.getH_jd());
ps.setInt(5, info.getH_shi());
ps.setInt(6, info.getH_ting());
ps.setString(7, info.getH_type());
ps.setDouble(8, info.getH_price());
ps.setString(9, info.getH_per());
ps.setString(10, info.getH_tel());
ps.setString(11, info.getH_remark());
int count = ps.executeUpdate();
if (count > 0) {
isflat = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeConn(conn);
}
return isflat;
}
/**
* 获取所有租房信息
*
* @return
*/
public List getAllHouseInofo() {
List list = new ArrayList();
String sql = "select h_id,h_title,h_price,h_date from t_house";
Connection conn = getConn();
try {
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
House info = new House();
info.setH_id(rs.getInt("h_id"));
info.setH_title(rs.getString("h_title"));
info.setH_price(rs.getDouble("h_price"));
info.setH_date(rs.getDate("h_date"));
list.add(info);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeConn(conn);
}
return list;
}
/**
* 根据用户获取其发布的租房信息
*
* @param per
* @return
*/
public List getHouseInfoByPer(Users per) {
List list = new ArrayList();
String sql = "select h_id,h_title,h_price,h_date from t_house where p_id=?";
Connection conn = getConn();
ResultSet rs = null;
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, per.getId());
rs = ps.executeQuery();
while (rs.next()) {
House info = new House();
info.setH_id(rs.getInt("h_id"));
info.setH_title(rs.getString("h_title"));
info.setH_price(rs.getDouble("h_price"));
info.setH_date(rs.getDate("h_date"));
list.add(info);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeResultSet(rs);
// 关闭数据库连接
this.closeConn(conn);
}
return list;
}
/**
* 根据标题模糊查询
*
* @param key
* @return
*/
public List getHouseInfoBylike(String key) {
List list = new ArrayList();
String sql = "select h_id,h_title,h_price,h_date from t_house where h_title like ?";
Connection conn = getConn();
ResultSet rs = null;
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, "%" + key.trim() + "%");
rs = ps.executeQuery();
while (rs.next()) {
House info = new House();
info.setH_id(rs.getInt("h_id"));
info.setH_title(rs.getString("h_title"));
info.setH_price(rs.getDouble("h_price"));
info.setH_date(rs.getDate("h_date"));
list.add(info);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeResultSet(rs);
this.closeConn(conn);
}
return list;
}
/**
* 根据租房信息id获取租房信息
*
* @param h_id
* @return
*/
public House getHouseInfo(int h_id) {
House info = null;
String sql = "select * from t_house where h_id=?";
Connection conn = getConn();
ResultSet rs = null;
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, h_id);
rs = ps.executeQuery();
while (rs.next()) {
info = new House();
info.setH_id(rs.getInt("h_id"));
info.setH_title(rs.getString("h_title"));
info.setH_per(rs.getString("h_per"));
info.setH_tel(rs.getString("h_tel"));
info.setH_type(rs.getString("h_type"));
info.setH_shi(rs.getInt("h_shi"));
info.setH_ting(rs.getInt("h_ting"));
info.setH_price(rs.getDouble("h_price"));
info.setH_qx(rs.getString("h_qx"));
info.setH_jd(rs.getString("h_jd"));
info.setH_date(rs.getDate("h_date"));
info.setH_remark(rs.getString("h_remark"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeResultSet(rs);
this.closeConn(conn);
}
return info;
}
/**
* 修改租房信息
*
* @param info
* @return
*/
public boolean updateHouse(House info) {
boolean isflat = false;
String sql = "update t_house set h_title=?,h_qx=?,h_jd=?,h_shi=?,h_ting=?,h_type=?,h_price=?,h_per=?,h_tel=?,h_remark=? where h_id=?";
Connection conn = this.getConn();
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, info.getH_title());
ps.setString(2, info.getH_qx());
ps.setString(3, info.getH_jd());
ps.setInt(4, info.getH_shi());
ps.setInt(5, info.getH_ting());
ps.setString(6, info.getH_type());
ps.setDouble(7, info.getH_price());
ps.setString(8, info.getH_per());
ps.setString(9, info.getH_tel());
ps.setString(10, info.getH_remark());
ps.setInt(11, info.getH_id());
int count = ps.executeUpdate();
if (count > 0) {
isflat = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeConn(conn);
}
return isflat;
}
/**
* 删除租房信息
*
* @param id
* @return
*/
public boolean deleteHouseById(int id) {
boolean isflat = false;
String sql = "delete from t_house where h_id=?";
Connection conn = this.getConn();
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, id);
int ncount = ps.executeUpdate();
if (ncount > 0) {
isflat = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeConn(conn);
}
return isflat;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java框架房屋出租系统
共77个文件
class:20个
java:20个
jsp:11个
需积分: 9 33 下载量 126 浏览量
2009-03-28
12:44:14
上传
评论
收藏 442KB RAR 举报
温馨提示
自己刚学完struts做了这个系统,可能还不是很完善,仅给初学者学习使用struts框架
资源推荐
资源详情
资源评论
收起资源包目录
HouseRent.rar (77个子文件)
HouseRent
.project 1KB
.settings
.jsdtscope 406B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 300B
WebRoot
showone.jsp 3KB
showallhouse.jsp 1KB
WEB-INF
.struts-config.mex 48B
web.xml 1KB
struts-config.xml 2KB
lib
classes
com
ljf
dao
HouseDao.class 6KB
UserDao.class 2KB
BaseDao.class 2KB
manager
HouseManager.class 1KB
UserManager.class 696B
struts
UserLoginAction.class 2KB
SearchOneAction.class 2KB
UserLoginActionForm.class 769B
SearchHouseActionForm.class 590B
ExitAction.class 1KB
HouseAddAction.class 2KB
SelectAllHouseAction.class 2KB
SearchHouseAction.class 2KB
UserAddAction.class 2KB
UserAddActionForm.class 763B
UpdateActionForm.class 2KB
ApplicationResources.properties 84B
HouseAddActionForm.class 2KB
UpdateAction.class 2KB
model
House.class 3KB
Users.class 890B
index.jsp 3KB
userregister.jsp 4KB
addhouse.jsp 4KB
META-INF
MANIFEST.MF 39B
add.jsp 603B
error.jsp 831B
one.jsp 2KB
showmyhouse.jsp 1KB
images
middle2.jpg 9KB
middle4.jpg 9KB
bottom.jpg 14KB
error.jpg 2KB
error0.jpg 3KB
layout_24.gif 945B
middle1.jpg 33KB
middle.jpg 34KB
222.swf 300KB
top.jpg 46KB
search.jsp 1KB
style
btn.css 3KB
mycss.css 1KB
text.css 297B
welcome.jsp 908B
.myeclipse
src
com
ljf
dao
UserDao.java 2KB
BaseDao.java 1KB
HouseDao.java 6KB
manager
UserManager.java 576B
HouseManager.java 1KB
struts
ExitAction.java 708B
UpdateActionForm.java 2KB
UserLoginAction.java 1KB
SearchHouseActionForm.java 288B
SelectAllHouseAction.java 1000B
HouseAddActionForm.java 2KB
SearchOneAction.java 1KB
UserLoginActionForm.java 424B
UpdateAction.java 2KB
UserAddAction.java 963B
HouseAddAction.java 2KB
SearchHouseAction.java 1KB
UserAddActionForm.java 432B
ApplicationResources.properties 84B
model
Users.java 468B
House.java 2KB
.mystrutsdata 254B
.classpath 475B
共 77 条
- 1
资源评论
hellofengzi
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 高等数学第一章第二节数列的极限
- Python 版冒泡排序算法源代码
- tensorflow-gpu-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- Python版本快速排序源代码
- Python 语言版的快速排序算法实现
- 450815388207377安卓_base.apk
- 超微主板 X9DRE-TF+ bios 支持 nvme启动
- 基于Python通过下载气象数据和插值拟合离散数据曲线实现对寒潮过程的能量分析
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功