在service层处理事务,dao层不做任何处理,直接把异常抛出。
解决方案 »
- ssh工程整合了 cxf 启动成功,但是访问失败
- java 执行shell“ls > & /root/a.txt”出错“ls: /root/a.txt: No such file or directory”
- 连接不到数据库
- 连接数据库异常
- 一个关于Servlet的forward问题
- Hibernate方面的问题急需请教:
- 关于jsp使用数据源的问题,请问有人知道出现了什么错误?
- !!!100分,请教Eclipse中的tags-bean标签问题~
- 讨论:从现实开发的角度来看现有的技术基础上采用web services的理由?
- 五子棋代码求解惑
- 请问以下各位高手!tomcat+Jboss的最新版本是多少???
- 请教各位,有没有通用的Web service生成工具?
package com.dao;
public class ADao
{
public boolean insert(Object A) throws SQLException
{
String sql="insert into table values(?,?,?)";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:sid","scott","tiger");
//此处要不要禁用自动提交呢?
conn.setAutoCommit(false);
PreparedStatement pstmt=conn.createPreparedStatement();
pstmt.setString(1,"a");
...
pstmt.executeUpdate(sql);
}catch(ClassNotFoundException cnfe)
{
}catch(SQLException se)
{
throw SQLException;
}
}
//....
}public class BDao
{
public boolean insert(Object B) throws SQLException
{
String sql="insert into table values(?,?,?)";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:sid","scott","tiger");
//此处要不要禁用自动提交呢?
conn.setAutoCommit(false);
PreparedStatement pstmt=conn.createPreparedStatement();
pstmt.setString(1,"a");
...
pstmt.executeUpdate(sql);
}catch(ClassNotFoundException cnfe)
{
}catch(SQLException se)
{
throw SQLException;
}
}
//....
}package com.service;
public class Service
{
public boolean addNewBusiness(Object A,Object B)
{
ADao aDao=new ADao();
BDao bDao=new BDao();
if(....)
{
aDao.insert(A);
bDao.insert(B);
///请问这里如何提交?
}
else
{
///请问这里如何回滚?
}
}
//.....
}
那如果像你说的那样的话,DAO和Service层有何区别呢?
本人另开贴散分,说到做到。