我是这样理解DAO的,对吗?
我在写一个WEB的轻型应用,想应用DAO,我想DAO模式的主要目的是,使具体的数据库SQL语句与应用分离,我是这样用的,是不是DAO模式
1.INewsDao 接口
public interface INewsDao {
public List getNews(int count,Date today);
...
}
2.NewsDaoOracleImpl 是对应Oracle数据库的一个实现
public class NewsDaoOracleImpl implements INewsDao {
private static NewsHome home=new NewsHome(); //EJB或JDO对象
public List getNews(int count, Date today) {
String sql="select * from news where ...";
List myList=home.getNews(sql); //EJB或JDO调用
return myList;
}
}
3.NewsDaoFactory 类工厂public class NewsDaoFactory {
//返回INewsDao接口类型
public static INewsDao getDao() {
INewsDao newdao = null;
try {
newdao = (INewsDao) Class.forName(
"my.dao.NewsDaoOracleImpl")
.newInstance();
} catch (ClassNotFoundException ce) {
System.out.println("get News Dao ClassNot Found");
ce.printStackTrace();
System.out.println("get News Dao ClassNot Found end...");
} catch (Exception ce) {
System.out.println("get News Dao Exception");
ce.printStackTrace();
System.out.println("get News Dao Exception end...");
}
return newdao;
}
}
多谢!