/**
*
*/
package com.DaoImpl;
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.Dao.AirConditionDao;
import com.Dao.DBHelperDao;
import com.Entity.AirCondition;
/**
* @author student
*
*/
public class AirConditionDaoImpl extends DBHelperDao implements AirConditionDao {
Connection conn = null;
PreparedStatement psta = null;
ResultSet rs = null;
/***
* 增加一条产品信息
*/
public int AddAriCondition(AirCondition ari) {
// TODO Auto-generated method stub
int num = 0;
try {
conn = super.GetConnection();
String sql = "insert into air_condition( brand, price, prod_area, ari_func, color) values(?, ?, ?, ?, ?)";
System.out.println(sql);
psta = conn.prepareStatement(sql);
psta.setString(1, ari.getBrand());
psta.setInt(2, ari.getPrice());
psta.setString(3, ari.getProdArea());
psta.setString(4, ari.getAir_func());
psta.setString(5, ari.getColor());
num = psta.executeUpdate();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(num > 0)
{
System.out.println("数据插入成功了!");
}else
{
System.out.println("插入数据失败!");
}
super.CloseAll(conn, psta, null);
}
return num;
}
/***
* 根据信息 ID 删除空调信息
*/
public int DeleteAriConditionById(String ids) {
// TODO Auto-generated method stub
int num = 0;
try {
conn = super.GetConnection();
String sql = "Delete from dbo.air_condition where id in (" + ids + ")";
System.out.println(sql);
psta = conn.prepareStatement(sql);
num = psta.executeUpdate();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(num > 0)
{
System.out.println("数据删除成功了!");
}else
{
System.out.println("数据删除失败!");
}
super.CloseAll(conn, psta, null);
}
return num;
}
/***
* 查询所有的信息
*/
public List GetAriCondition(String brand, String airFunc, String color) {
// TODO Auto-generated method stub
List list = new ArrayList();
try {
conn = super.GetConnection();
String sql = "select * from dbo.air_condition where 1=1 ";
if(brand != null && !brand.equals(""))
{
sql += " and brand = '" + brand + "'";
}
if(airFunc != null && !airFunc.equals(""))
{
sql += " and ari_func like '%" + airFunc + "%'";
}
if(color != null && !color.equals("") && !color.equals("--请选择--"))
{
sql += " and color = '" + color + "'";
}
System.out.println(sql);
psta = conn.prepareStatement(sql);
rs = psta.executeQuery();
while(rs.next())
{
AirCondition air = new AirCondition();
air.setId(rs.getInt("id"));
air.setBrand(rs.getString("brand"));
air.setPrice(rs.getInt("price"));
air.setProdArea(rs.getString("prod_area"));
air.setAir_func(rs.getString("ari_func"));
air.setColor(rs.getString("color"));
list.add(air);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
super.CloseAll(conn, psta, rs);
}
return list;
}
/***
* 根据信息 ID 查询空调信息
*/
public AirCondition GetAriCondition(int id) {
// TODO Auto-generated method stub
AirCondition air = new AirCondition();
try {
conn = super.GetConnection();
String sql = "select * from dbo.air_condition where id = ? ";
System.out.println(sql);
psta = conn.prepareStatement(sql);
psta.setInt(1, id);
rs = psta.executeQuery();
while(rs.next())
{
air.setBrand(rs.getString("brand"));
air.setPrice(rs.getInt("price"));
air.setProdArea(rs.getString("prod_area"));
air.setAir_func(rs.getString("ari_func"));
air.setColor(rs.getString("color"));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
super.CloseAll(conn, psta, rs);
}
return air;
}
/***
* 根据信息 ID 更新空调信息
*/
public int ModifyAriConditionById(AirCondition ari) {
// TODO Auto-generated method stub
int num = 0;
try {
conn = super.GetConnection();
String sql = "Update dbo.air_condition set brand=?, price=?, prod_area=?, ari_func=?, color=? where id= ?";
System.out.println(sql);
psta = conn.prepareStatement(sql);
psta.setString(1, ari.getBrand());
psta.setInt(2, ari.getPrice());
psta.setString(3, ari.getProdArea());
psta.setString(4, ari.getAir_func());
psta.setString(5, ari.getColor());
psta.setInt(6, ari.getId());
num = psta.executeUpdate();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(num > 0)
{
System.out.println("数据更新成功了!");
}else
{
System.out.println("更新数据失败!");
}
super.CloseAll(conn, psta, null);
}
return num;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于JSP开发的空调管理系统(含数据库)
共28个文件
jsp:7个
class:4个
java:4个
需积分: 10 9 下载量 143 浏览量
2011-07-02
15:45:36
上传
评论
收藏 1.45MB RAR 举报
温馨提示
基于MyEclipse7.5 和 SQL Server 2005开发的空调管理系统。jsP技术。实现了增删改查
资源推荐
资源详情
资源评论
收起资源包目录
AirCondition.rar (28个子文件)
AirCondition
.project 1KB
.settings
.jsdtscope 500B
org.eclipse.jdt.core.prefs 330B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 309B
WebRoot
WEB-INF
web.xml 371B
lib
sqljdbc4.jar 455KB
classes
com
DaoImpl
AirConditionDaoImpl.class 6KB
Dao
AirConditionDao.class 406B
DBHelperDao.class 2KB
Entity
AirCondition.class 1KB
index.jsp 834B
META-INF
MANIFEST.MF 36B
CSS
CSS.css 66B
Web
ModifyAir.jsp 4KB
index.jsp 7KB
AddAir.jsp 4KB
manage
doModifyAir.jsp 2KB
doAddAir.jsp 2KB
doDeleteAir.jsp 1KB
.myeclipse
src
com
DaoImpl
AirConditionDaoImpl.java 6KB
Dao
DBHelperDao.java 1KB
AirConditionDao.java 455B
Entity
AirCondition.java 986B
airConditionDB
exam_db_log.ldf 1024KB
exam_db.mdf 3MB
.classpath 433B
共 28 条
- 1
资源评论
axing
- 粉丝: 18
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功