;System.out.println (rs.getString(1));
System.out.println("013:return record success!"
;...
What way is right to invok ResultSet form JavaBean in Servlet?
My way is error,now?
| cinc 回复于:2002-10-30 00:12:56 |
| [这个贴子最后由cinc在 2002/10/30 00:16am 编辑] You can use DAO Pattern and MVC Framework: Servlet, JSP -> JavaBean and DAO -> Database Servlet or JSP is the View layer of MVC Framework. It must not contain any codes that directly access database. JavaBean and DAO is the Model layer of MVC Framework. JavaBeans is the representation of table in database You can place business code in DAO Object, including code communicating with database. For example: If you have a table in database called : article create table article( id integer, title char(10), content char(30) ) 1.Model layer : JavaBean and DAO Object You can create a JavaBean to represent an article in database public class Article{ int id; String title; String content; public void set...(){ } public ... get...(){ } ... } we ususally use DAO Object to access database, for article, we create: public class ArticleDAO{ /** * find one article, return an article */ public Article findById(int id){ // execute SQL : select title, content from article where id = 10; Article article = new Article(); article.setId(id); article.setTitle(title); article.setContent(content); return article; } /** * find all the articles which contains the keyword, return a vector * containing these articles */ public Vector findByKeyword(String keyword){ Vector resultVector = new Vector(); // execute SQL : select title, content from article where content like "%keyword%"; while (resultset.next){ Article article = new Article(); article.setId(id); article.setTitle(title); article.setContent(content); resultVector.add (article); } return resultVector; } } 2.View Layer : servlet or jsp /** * user want to find all the article that contain the keyword */ public void doGet(...){ String keyword = getParameter("keyword" ;ArticleDAO articleDAO = new ArticleDAO(); Vector resultVector = articleDAO.findByKeyword(keyword); // display each article in resultVector } DAO Pattern is a widely used pattern in web development of servlet and jsp more detail: http://java.sun.com/blueprints/patterns/DAO.html Other consideration about design pattern: use Factory to Create DAO Object public class DAOFactory{ public ArticleDAO getArticleDAO(){ ... } ... } Factory is an Singleton :) |
| bill1 回复于:2002-10-30 09:36:38 |
| No, my operation bean encapsuled in PL/SQL. |
| cinc 回复于:2002-10-30 10:40:50 |
| 呵呵,没做过,不过应该是一样的。 你先写个 application (带 main 的)试试。 :) |
| pilgram 回复于:2002-11-02 11:44:03 |
| </pre> because the v_cursor is not initialized ,it's an invalidate cursor please refer to "http://www.csee.umbc.edu/help/oracle8/java.815/a64685/samapp3.htm" you can change it as following: oracle's package P_T_Reoprt create or replace package P_T_Reoprt type v_cursor is ref cursor return table_name%ROWTYPE; function T_Reoprt (j varchar2) return v_cursor; end P_T_Reoprt; |






