package com.lgx.dal.Sql;
import java.util.ArrayList;
import java.sql.Types;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.CallableStatement;
import java.sql.Connection;
import com.lgx.Models.Boss;
import com.lgx.idal.IBoss;
import com.lgx.dbClose.Close;
import com.lgx.Models.Boss;
import com.lgx.Models.Sex;
public class SqlBossOper implements IBoss {
public SqlBossOper()
{
}
public int delete(int id) {
// TODO Auto-generated method stub
CallableStatement cs=null;
Connection connection=SqlHelper.GetConnection();
int count=0;
try
{
cs=connection.prepareCall("{call proc_boss_delete(@id=?)}");
cs.setInt(1, id);
count=cs.executeUpdate();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
return 0;
}
finally
{
Close.CloseCallableStatement(cs);
Close.CloseConnection(connection);
}
return count;
}
public int insert(Boss boss) {
// TODO Auto-generated method stub
CallableStatement cs=null;
Connection connection=SqlHelper.GetConnection();
int count=0;
try
{
cs=connection.prepareCall("{call proc_boss_insert(?,?,?,?,?)}");
cs.setString(1, boss.getName());
cs.setString(2, (boss.getSex()==Sex.Boy?"男":"女"));
cs.setInt(3, boss.getAge());
cs.setString(4, boss.getJob());
cs.setString(5, boss.getAddress());
count=cs.executeUpdate();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
ex.printStackTrace();
return 0;
}
finally
{
Close.CloseCallableStatement(cs);
Close.CloseConnection(connection);
}
return count;
}
public ArrayList<Boss> selectAll() {
// TODO Auto-generated method stub
Connection connection=SqlHelper.GetConnection();
CallableStatement cs=null;
ArrayList<Boss> list=new ArrayList<Boss>();
ResultSet rs=null;
try
{
cs=connection.prepareCall("{call proc_boss_select}");
rs=cs.executeQuery();
while(rs.next())
{
Boss boss=new Boss(rs.getInt(1),rs.getString(2),(rs.getString(3).equals("男")?Sex.Boy:Sex.Girl),rs.getInt(4),rs.getString(6),rs.getString(5));
list.add(boss);
}
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
return null;
}
finally
{
Close.CloseResultSet(rs);
Close.CloseCallableStatement(cs);
Close.CloseConnection(connection);
}
return list;
}
public int update(Boss boss) {
// TODO Auto-generated method stub
Connection connection=SqlHelper.GetConnection();
CallableStatement cs=null;
int count=0;
try
{
cs=connection.prepareCall("{call proc_boss_update(?,?,?,?,?,?)}");
cs.setString(1, boss.getName());
cs.setString(2, (boss.getSex()==Sex.Boy?"男":"女"));
cs.setInt(3, boss.getAge());
cs.setString(4, boss.getJob());
cs.setString(5, boss.getAddress());
cs.setInt(6, boss.getId());
count=cs.executeUpdate();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
return 0;
}
finally
{
Close.CloseCallableStatement(cs);
Close.CloseConnection(connection);
}
return count;
}
public Boss selectById(int id)
{
Connection connection=SqlHelper.GetConnection();
CallableStatement cs=null;
ResultSet rs=null;
Boss boss=null;
try
{
cs=connection.prepareCall("{call proc_boss_selectById(?)}");
cs.setInt(1, id);
rs=cs.executeQuery();
if(rs.next())
{
boss=new Boss();
boss.setId(rs.getInt(1));
boss.setName(rs.getString(2));
boss.setSex((rs.getString(3).equals("男")?Sex.Boy:Sex.Girl));
boss.setAge(rs.getInt(4));
boss.setJob(rs.getString(5));
boss.setAddress(rs.getString(6));
}
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
return null;
}
finally
{
Close.CloseResultSet(rs);
Close.CloseCallableStatement(cs);
Close.CloseConnection(connection);
}
return boss;
}
}
java抽象工厂增删改查
需积分: 10 162 浏览量
2008-12-16
01:01:56
上传
评论 1
收藏 749KB RAR 举报
freeworrier
- 粉丝: 3
- 资源: 16
最新资源
- F103-霸道开发板2.8寸电阻触摸屏例程.rar
- Google(高德)地图瓦片python代码下载
- Python实现输出杨辉三角形
- polsarpro官方教程、操作说明 PolSARpro v5.0 Software Training Course
- STM32 TouchGFX的使用二图片显示
- buildx镜像文件,也可以通过网上其他方式获取
- 【中级软件设计师】上午题12-软件工程(2):单元测试、黑盒测试、白盒测试、软件运行与维护
- 免费计算机毕业设计-医院住院管理系统的设计与实现(包含代码+论文)
- tt100k数据转换yolo格式
- 免费计算机毕业设计-学生在线网络考试系统的设计与实现(包含论文+源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈