利用JDBC RowSet讓EJB返回數据集(手記)
**************************************************************************
前言:
前几日在Weblogic6.1上試驗使用數据集OK(EJB和客戶端都在Weblogic上),后來將
客戶端部署到另外一臺服務器上(運行Resin),想由Resin上的JSP客戶端調用來獲得
Weblogic上的EJB返回的數据集,發現行不通.
經過日夜搜索,終于發現一偏關于JDBC RowSet的文章(JDBC 2.0 Optional Package API),
正是我想要的.
馬上行動!
**************************************************************************
注意:安以下步驟部署你必須熟悉Weblogic6.1的EJB部署,數据源部署.
1.到http://developer.java.sun.com/developer/earlyAccess/下載rowset.jar
//JDBC RowSet The three JDBC RowSet implementations in this release demonstrate some of the many possibilities for implementing the javax.sql.RowSet interface, which is part of the JDBC 2.0 Optional Package API. (June 30, 2000)
2.將rowset.jar放到你的CLASSPATH中.(我使用的是Weblogic6.1)
3.寫你的EJB,如下列:
************************************************************************
CoffeesEJB.java
************************************************************************
import java.sql.*;
import javax.sql.*;
import sun.jdbc.rowset.*; //倒入rowset.jar類
import javax.naming.*;
import javax.ejb.*;
public class CoffeesEJB implements SessionBean {
private SessionContext sc = null;
private Context ctx = null;
private DataSource ds = null;
public CoffeesEJB () {}
public void ejbCreate() throws CreateException {
try {
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("bbb.OracleThintxds"); //數据源
}
catch (Exception e) {
System.out.println(e.getMessage());
throw new CreateException();
}
}
public RowSet getCoffees() throws SQLException {
Connection con = null;
ResultSet rs;
CachedRowSet crs;
try {
con = ds.getConnection("system", "command1"); //EJB Server的用戶和密碼,我用的是Weblogic6.1
&n
**************************************************************************
前言:
前几日在Weblogic6.1上試驗使用數据集OK(EJB和客戶端都在Weblogic上),后來將
客戶端部署到另外一臺服務器上(運行Resin),想由Resin上的JSP客戶端調用來獲得
Weblogic上的EJB返回的數据集,發現行不通.
經過日夜搜索,終于發現一偏關于JDBC RowSet的文章(JDBC 2.0 Optional Package API),
正是我想要的.
馬上行動!
**************************************************************************
注意:安以下步驟部署你必須熟悉Weblogic6.1的EJB部署,數据源部署.
1.到http://developer.java.sun.com/developer/earlyAccess/下載rowset.jar
//JDBC RowSet The three JDBC RowSet implementations in this release demonstrate some of the many possibilities for implementing the javax.sql.RowSet interface, which is part of the JDBC 2.0 Optional Package API. (June 30, 2000)
2.將rowset.jar放到你的CLASSPATH中.(我使用的是Weblogic6.1)
3.寫你的EJB,如下列:
************************************************************************
CoffeesEJB.java
************************************************************************
import java.sql.*;
import javax.sql.*;
import sun.jdbc.rowset.*; //倒入rowset.jar類
import javax.naming.*;
import javax.ejb.*;
public class CoffeesEJB implements SessionBean {
private SessionContext sc = null;
private Context ctx = null;
private DataSource ds = null;
public CoffeesEJB () {}
public void ejbCreate() throws CreateException {
try {
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("bbb.OracleThintxds"); //數据源
}
catch (Exception e) {
System.out.println(e.getMessage());
throw new CreateException();
}
}
public RowSet getCoffees() throws SQLException {
Connection con = null;
ResultSet rs;
CachedRowSet crs;
try {
con = ds.getConnection("system", "command1"); //EJB Server的用戶和密碼,我用的是Weblogic6.1
&n
| 对此文章发表了评论 |
