DAOException 和ServiceException
来源:互联网 发布:vb从入门到精通第三版 编辑:程序博客网 时间:2024/06/07 18:54
后期用到hibernate和spring可能就不需要这些了
1.DAOException
package com.neusoft.trainingcenter.hr.utils;
public class DaoException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;
public DaoException() {
}
public DaoException(String arg0) {
super(arg0);
}
public DaoException(Throwable arg0) {
super(arg0);
}
public DaoException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
}
2.ServiceException
package com.neusoft.trainingcenter.hr.utils;
public class ServiceException extends RuntimeException {
private static final long serialVersionUID = 1L;
public ServiceException() {
}
public ServiceException(String arg0) {
super(arg0);
}
public ServiceException(Throwable arg0) {
super(arg0);
}
public ServiceException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
}
3.Dao层的demo:
/**
* 增加部门
*
* @param section
* section对象
*/
public void addSection(Section section) {
String sql = "insert into section(" + "snumber," // 标识符
+ "sno," // 部门编号
+ "sname," // 部门名称
+ "stype," // 部门类型
+ "sphone," // 电话
+ "sfax," // 传真
+ "sdes," // 描述
+ "supper," // 上级部门
+ "s_setdate)" // 成立日期
+ "values(s.nextval, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement pstmt = null;
try {
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, section.getSno());
pstmt.setString(2, section.getSname());
pstmt.setString(3, section.getStype());
pstmt.setString(4, section.getSphone());
pstmt.setString(5, section.getSfax());
pstmt.setString(6, section.getSdes());
pstmt.setString(7, section.getSupper());
pstmt.setDate(8, section.getSdate());
pstmt.executeUpdate();
} catch (SQLException e) {
throw new DaoException("Error on adding section", e);
} finally {
DBUtils.closeStatement(pstmt);
}
}
4:service层demo:
public void addSection(Section section) {
// 数据库连接
// 声明一个部门数据访问对象
// 开始数据库交互
// 调用增加部门方法
// 数据库提交
// 捕捉该过程中异常
Connection conn = null;
try {
conn = DBUtils.getConnection();
SectionDao sectionDao = new SectionDaoImpl(conn);
DBUtils.beginTransaction(conn);
sectionDao.addSection(section);
DBUtils.commit(conn);
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
DBUtils.rollback(conn);
throw new ServiceException("添加部门错误", e);
} finally {
DBUtils.closeConnection(conn);
}
}
- DAOException 和ServiceException
- DAOException
- DaoException
- 整合spring4和hibernate4出现问题———org.hibernate.service.spi.ServiceException:
- Hibernate提示service.spi.ServiceException
- java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException错误
- nested exception is java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
- 【Java-Webservice】java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException错误
- java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException错误
- java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException错误
- java.lang.ClassFormatError: Absent Code attribute...javax/xml/rpc/ServiceException
- org.nutz.dao.DaoException: Need non-arg constructor : class org.dom4j.tree.DefaultElement
- com.mtconnect.exception.DAOException: java.sql.SQLException: number of allocated descriptors exceede
- tomcat 启动webservice报java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
- SSH 整合 nested exception is org.hibernate.service.spi.ServiceException错误
- The type javax.xml.rpc.ServiceException cannot be resolved.It is indirectly……
- org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine
- com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: com/yammer/metrics/core/Gauge
- 页面请求过滤器
- C++、Objective-C 混合编程
- C#操作Excel文件(读取Excel,写入Excel) .
- HttpWatch学习笔记一
- DB数据库语句,在这里直接把老师写的拷过来了,要配置数据库连接池
- DAOException 和ServiceException
- linux下常用命令
- 我与你同在 保重
- HttpWatch学习笔记二
- OpenRTSP分析一
- mmap例子
- Visual Studio 2005 无法创建"智能设备"解决办法 .
- 正则表达式
- C语言教程第一章: C语言概论