Displaying ResultSet in DataTable component

Say my program codes have created a ResultSet object by applying some SQL query into the database tables.Now I just want to display the contents of that ResultSet object in the JSC DataTable component. Is it possible? If so, how?Thank you.
[274 byte] By [MISS_DUKE] at [2007-11-26 9:25:35]
# 1

One possibility is to extend the ObjectListDataProvider class a and bind the data table component to the data provider.

See Winston's blogs for info on the object list data provider (http://blogs.sun.com/roller/page/winston)

Here is an older tutorial about the Data Table component. Maybe you can get something useful out of that.

http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2004q 2/datatables.html

jetsons at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 2

Hi,

I want to do the same thing than MISS_DUKE but I have read on the following adress : http://developers.sun.com/prodtech/javatools/jscreator/reference/fi/2/data-prov ider.html

that we should have a Resultset Table Data Provider and it is not my case.

Is it more useful than doing what jetsons said ? (I don't think so but i want to know more about those Resultset Table Data Providers)

Thx

Marc_Oz_Sar at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 3
Resultset Table Data Providers shouls ease the task very much, but my JSC version also not including that. I wonder how to import taht !!Are anyone using Resultset Table Data Providers? Thank you.
MISS_DUKE at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 4

> Say my program codes have created a ResultSet

> object by applying some SQL query into the

> database tables.

>

> Now I just want to display the contents of that

> ResultSet object in the JSC DataTable

> component. Is it possible? If so, how?

How come you are not using the cached rowset data provider as explained in :

http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/dat aboundcomponents.html

http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/dat aproviders.html

jetsons at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 5

Resultset Table Data Providers is listed in the list of available data providers in the following article: (see figure 1 there)

http://developers.sun.com/prodtech/javatools/jscreator/reference/fi/2/data-prov ider.html

But that is not available in the current version of the IDE. Are there any way to import that?

Thank you very much.

MISS_DUKE at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 6

Hello,

I did not write the article so I cannot comment on the article. I do not know why it shows a result set data provider. The IDE does not offer a result set data provider.

I can comment on the tutorials. The tutorials and the Field Guide discuss the data providers that are available. There is a new tutorial that will be out today or tomorrow that shows how to handle data using the Hibernate framework.

As asked before, what is it that you are trying to do that the cached row set data provider (which handles result sets) does not handle?

jetsons at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 7

It is very difficult using cashed rowset data provider, If you want to display rows from more than one database tables on a single data table component.

(Unless you visually join cashed rowsets in the query editor, but note visually joining cashed rowsets are not always possible specially when you apply complecated sql query)

Thank you.

MISS_DUKE at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 8

Hi,

The Visual Query Editor exists for simplifying typical tasks. You do not have to use the visual query editor.

Your options are to paste your sql into the Query pane in the Visual Query Editor or to edit, in the session bean's _init() method the rowset's command:

stateRowSet.setCommand("SELECT ALL VIR.STATE.STATEID, \nVIR.STATE.STATENAME \nFROM VIR.STATE\nWHERE VIR.STATE.STATENAME = ? ");

The Visual Query Editor will tell you that it has trouble interpreting your advanced command but you can ignore that. It just won't be able to visually display your query in the top 2 panes of the query editor.

jetsons at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 9

Hi,

I think i have found a way to do what we want to do :

As written in Winston Prakash's Weblog (http://blogs.sun.com/roller/page/winston),

1) I have created a java class "ResultRowDataProvider" that extends ListObjectDataProvider and that contains a method that fill a list from the resultset. (Later, this list will be automatically used to fill the Table Component)

That is to say :

public class ResultRowDataProvider extends ObjectListDataProvider{

private List resultList = new ArrayList();

/** Creates a new instance of ResultRowDataProvider */

public ResultRowDataProvider() {

setUserResizable(true);

}

public void fillResultList(ResultSet rs){

try{

rs.beforeFirst();

while(rs.next())

resultList.add(new ResultRow(rs.getString(1), rs.getString(2)));

} catch(SQLException sqle){}

setList(resultList);

}

public int getNbRows(){

return this.resultList.size();

}

}

2) I have created a java class "ResultRow" where I defined private attributes that the ResultRowDataProvider will provide.

That is to say :

public class ResultRow(){

private String field1;

private String field2;

public ResultRow(String field1, String field2){

this.field1 = field1;

this.field2 = field2;

}

public String getField1(){

return this.field1;

}

public String getField2(){

return this.field2;

}

public void setField1(String field1){

this.field1 = field1;

}

public void setField2(String field2){

this.field2 = field2;

}

}

3) I finally added the following line to the init( ) method in SessionBean1.java :

resultRowDataProvider = new ResultRowDataProvider();

Then it is compulsory to clean and build the project, to close the project and to reopen it so that the table component layout will take into account the ResultRowDataProvider.

I chose it, but it didn't display the two fields I defined (field1 and field2)

whereas Winston said it should display them. So I defined the table columns myself using as value : #{currentRow.getValue('field1')} for the field1 column.

It worked at runtime.

Now jetsons, I would like to tell you that I personnaly wanted to fill programmatically the Table Component because I am using an Oracle 9.2.0.1 database. In the first version of my project, i used the CachedRowSet. Then I read that i had to use OracleCachedRowSet using ocrs12.jar. But after many bugs at runtime, I had a look to forums and I read that :

"JDBC drivers provided by Oracle are not suitable for Sun Java Studio Creator, and are not supported. Oracle drivers currently available do not fully implement the JDBC 3.0 Specification. Sun Java Studio Creator requires certain schema information at design time that Oracle drivers do not provide."

In fact we can use DataDirect but ...

Filling programmatically a Table Component is a database-independant way ;)

Thank you for your help jetsons and MISS_DUKE.

Marc_Oz_Sar at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...
# 10
For others following this thread, a new tutorial has steps for using an object list data provider: http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/hib ernate.html
MrsJetsons at 2007-7-7 0:02:55 > top of Java-index,Development Tools,Java Tools...