亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3281 | 回復(fù): 4
打印 上一主題 下一主題

What way is right to invok ResultSet form JavaBean in Servle [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2002-10-29 14:04 |只看該作者 |倒序瀏覽
oracle's package P_T_Reoprt

create or replace package P_T_Reoprt
as
type v_cursor is ref cursor&#59;
function T_Reoprt (j varchar2) return v_cursor&#59;
end P_T_Reoprt&#59;

create or replace package body P_T_Reoprt
as
function T_Reoprt (j varchar2) return v_cursor
is
rc v_cursor&#59;
begin
  open rc for select * from customer where customer.sex = j&#59;
  return rc&#59;
end&#59;
end P_T_Reoprt&#59;

------------------------------------------------

DBConnection.java(a method of the javabean's source)
....
  public ResultSet executeProduce(){
    rs = null&#59;
    try {
    //connect the database
    conn = DriverManager.getConnection("jdbcracle:thin192.168.0.176:1521:yzttest","bill","bill&quot&#59;
    System.out.println("004:connection success!&quot&#59;
    // Prepare a PL/SQL call
    CallableStatement call =  conn.prepareCall ("{?=call P_T_Reoprt.T_Reoprt(?)}&quot&#59;
    System.out.println("005:prepare PL/SQL Call success!&quot&#59;
    // Find out all Record
    call.registerOutParameter (1,OracleTypes.CURSOR)&#59;
    call.setString (2,"M&quot&#59;
    System.out.println("006L/SQL define success !&quot&#59;
    call.execute ()&#59;
    System.err.println("007L/SQL execute success!&quot&#59;
    ResultSet rs = (ResultSet)call.getObject (1)&#59;
    System.out.println("008:take resultset success!&quot&#59;
    }
    catch(SQLException ex) {
    System.err.println("012:fail to DBConnection.executeProduce: " + ex.getMessage())&#59;
    }
    return rs&#59;
  }
....

------------------------------------------------

when i invok that DBConnection's executeProduce method in the Servlet, that had happened and error when execute at "while(rs.next())"
...
    DBConnection JavaBean = new DBConnection()&#59;
    System.out.println("001:JavaBean instance success!&quot&#59;
    ResultSet rs=JavaBean.executeProduce()&#59;
    System.out.println("002:method invok success!&quot&#59;
    while (rs.next())//<<--------------that has error
    System.out.println(&quot;018:there have record!&quot;)&#59;
    System.out.println (rs.getString(1))&#59;
    System.out.println(&quot;013:return record success!&quot;)&#59;
...


What way is right to invok ResultSet form JavaBean in Servlet?
My way is error,now?


論壇徽章:
0
2 [報告]
發(fā)表于 2002-10-30 00:12 |只看該作者

What way is right to invok ResultSet form JavaBean in Servle

[這個貼子最后由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&#59;
  String title&#59;
  String content&#59;
  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&#59;
    Article article = new Article()&#59;
    article.setId(id)&#59;
    article.setTitle(title)&#59;
    article.setContent(content)&#59;
    return article&#59;
  }
  
  /**
   * find all the articles which contains the keyword, return a vector
   * containing these articles
   */
  public Vector findByKeyword(String keyword){
    Vector resultVector = new Vector()&#59;
    // execute SQL : select title, content from article where content like &quot;%keyword%&quot;&#59;
    while (resultset.next){
      Article article = new Article()&#59;
      article.setId(id)&#59;
      article.setTitle(title)&#59;
      article.setContent(content)&#59;
      resultVector.add (article)&#59;
    }
    return resultVector&#59;
  }
}


2.View Layer : servlet or jsp
/**
  * user want to find all the article that contain the keyword
  */
public void doGet(...){
  String keyword = getParameter(&quot;keyword&quot&#59;
  ArticleDAO articleDAO = new ArticleDAO()&#59;
  Vector resultVector = articleDAO.findByKeyword(keyword)&#59;
  // 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

:)

論壇徽章:
0
3 [報告]
發(fā)表于 2002-10-30 09:36 |只看該作者

What way is right to invok ResultSet form JavaBean in Servle

No, my operation bean encapsuled in PL/SQL.

論壇徽章:
0
4 [報告]
發(fā)表于 2002-10-30 10:40 |只看該作者

What way is right to invok ResultSet form JavaBean in Servle

呵呵,沒做過,不過應(yīng)該是一樣的。
你先寫個 application (帶 main 的)試試。

:)

論壇徽章:
0
5 [報告]
發(fā)表于 2002-11-02 11:44 |只看該作者

What way is right to invok ResultSet form JavaBean in Servle

</pre>;
because the v_cursor is not initialized ,it's an invalidate cursor
please refer to &quot;http://www.csee.umbc.edu/help/oracle8/java.815/a64685/samapp3.htm&quot;
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&#59;
function T_Reoprt (j varchar2) return v_cursor&#59;
end P_T_Reoprt&#59;



您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP