我估计他是想考你hibernate的东西哦!

解决方案 »

  1.   

    我想楼主应聘的多半是数据库操作方面的工作,很大可能就是搞网络的,对吗?DAO 就是 database access object,是一个操作数据库的类,我们开发WEB系统一般分为:窗体、控制层、业务层,以形成开发的系统化,DAO就是我们的业务层,可以说是最底层!给你一个例子:
    public class ArticleDAO implement BaseDAO { public ArticleDAO(Connection conn) {
    super(conn)
    {
    //在里面实现连接数据库的方法
    };
    } /**由文章id获得文章对象
     * 
     * @param articleId
     * @return
     * @throws SQLException
     * 
     * @author bill wu   [email protected]
     */
    public Article findArticle(int articleId) throws SQLException { ArrayList ar = new ArrayList(); String sql = "select * from wap_article where article_id =?"; PreparedStatement pstmt = conn.prepareStatement(sql);
    pstmt.setString(1, articleId + "");
    ResultSet rs = pstmt.executeQuery();
    Article article = null;
    if (rs.next()) {
    article = map(rs);
    } return article;
    }懂了吗?其实我认为续承一个类更好:
    public class ArticleDAO extends BaseDAO { public ArticleDAO(Connection conn) {
    super(conn);
    } /**由文章id获得文章对象
     * 
     * @param articleId
     * @return
     * @throws SQLException
     * 
     * @author bill wu   [email protected]
     */
    public Article findArticle(int articleId) throws SQLException { ArrayList ar = new ArrayList(); String sql = "select * from wap_article where article_id =?"; PreparedStatement pstmt = conn.prepareStatement(sql);
    pstmt.setString(1, articleId + "");
    ResultSet rs = pstmt.executeQuery();
    Article article = null;
    if (rs.next()) {
    article = map(rs);
    } return article;
    }我创建了一个java&&jsp群,里面有java高手,包括JAVA系统设计、数据安全、struts、linux安全、windows服务器安全等高手,欢迎加入:5933188 (QQ群)!进来吧!你的这个问题是最基本的了!