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.

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.

Similar Messages

  • Jsf datatable component + java.sql.SQLException

    I get the following error when implementing a JSF DataTable component using
    JDeveloper 10.1.3.1.
    javax.faces.FacesException: java.sql.SQLException: Io exception: Socket closed
    I am able to follow the article in this link:
    http://www.oracle.com/technology/oramag/oracle/06-jan/o16jsf.html
    I can get the table generated, but it occurred to me that the example in this article does not include logic to close the statement, resultset, and connection. Sure enough, I jumped out to the database and there were numerous inactive connections hanging around from my application.
    I added the following code before the return null statement from the article:
    finally {
    try {
    rs.close();
    stmt.close();
    c.close();
    catch (Exception e) {
    System.out.println("after close");
    So I need to know the proper procedure to closing the resultset, statement, and connection using a jsf datatable component.

    You need to make sure you're using the Oracle9i JDBC driver, or using the Oracle 8.1.7.2 JDBC driver as I mentioned above.
    If you are using JDeveloper9i release 9.0.2 or 9.0.3, the driver you need is in <jdevhome>\jdbc\lib
    Otherwise, you can also download the drivers from OTN.

  • How to bind table data to datatable component and show all the table data??

    I bind table to datatable component !
    The datatable has four rows,
    but the datatable alway show the first row data in its four rows,why??

    do you mean at design time or at runtime?
    at design time, the datatable uses generic fields to
    show if data type is numeric, text, date, etc...
    If this is at runtime,
    - what driver are you using?
    - how did you bind the data to the table?
    - what is the resulting code in the Java backing file?
    hth,
    -Alexis

  • My 4s worked fine displaying on tv with component cables, but after a while the tv displayed a black screen that said signal is playing on tv. Any input for a solution?

    My 4s cannot display on tv with component cable

    What TV (brand and model #)?
    Have you the Apple TV on another port? Used a different HDMI cable?
    Are you able to cycle through the resolutions via Apple TV settings?

  • Multiple DataSourceRef in DataTable component

    Dear All,
    I'm a newbie using JDeveloper 9.0.3 to develop a JSP application. I wonder if I can pass more than one DataSource to the DataTable component so that I can customize the component to get data from to DataSourceRef. Can anybody help?

    Dear All,
    I'm a newbie using JDeveloper 9.0.3 to develop a JSP application. I wonder if I can pass more than one DataSource to the DataTable component so that I can customize the component to get data from to DataSourceRef. Can anybody help?

  • Using Vector to display ResultSet on multiple pages

    Hi all,
    I want to use Vector for Displaying the ResultSet in multiple pages for my JSP.
    Can anybody assist me on how to display Resultset on multiple pages by using Vectors.
    Thanks for any help in advance.
    regards,
    savdeep

    Haii Pls go through the code
    Vector v=new Vectior()
    while(rs.next())
       v.add(rs.getString(column name));
    v //vector is readyyyyyregards
    Shanu

  • How can I display data from ResultSet to a component like jLable and JTable

    hi there
    My code as shown below
    boolean fillTable(int type){
            try{
                //model.setRowCount(0);
                if(type == 1){
                    System.out.println("line 1");
                    model = new DefaultTableModel(new Object [][] {   },
                            new String[] { "\u1200 Code", "Description" });
                    System.out.println("line 2");
                    while(lookup.rs2.next()){
                        System.out.println("line in while");
                        model.addRow(new String[] { lookup.rs2.getString("code"),
                            "\u1201 " + lookup.rs2.getString("amdescription")});
                          //System.out.println("While : " + lookup.rs2.getString("code") + " " +
                            //      lookup.rs2.getString("amdescription"));
                    lookup.rs2.last();
                    String str;
                    str =  new String (lookup.rs2.getString("amdescription"));
                    jLabel2.setText(str);
                    System.out.println("line 3");
                    tblLookup.setModel(model);
                    System.out.println("line 4");
                else if(type == 2){
                    System.out.println("line else if 1");
            }catch(Exception ex)    {
                System.out.println("Exception @ MilLookupDisplay fillTable : " + ex.getMessage());
                return false;
            return true;
        }I can read from access db and put the resultset on rs2 , it works fine
    my problem is when I try to display the data ( which is amharic unicode character ) on jTable and jLabel as shown it displays '???'
    besides I have checked the font by giving unicode like '\u1200' on both component displays it well
    so is there something to do before trying to display unicode characters from resultSet
    please I ' m waiting
    thanks a lot

    http://forum.java.sun.com/thread.jspa?threadID=5153938

  • Another nooblike question on DataTable and displaying ResultSets from db...

    Hey guys,
    I am trying to follow this tutorial example:
    http://www.oracle.com/technology/oramag/oracle/06-jan/o16jsf.html
    I am doing the second part of the example because the first part is not matching with what I want to do. So if you go through the code and I am sure for you gents its absolutely no problem to analyze and decipher the code. Basically I have a 2 column small table that I want to show up on the screen. I am using this as a learning example. I understand most of the code posted except for the variable 'column1' or 'column2' are. For the life of me I cannot figure out what it is. If someone can fill in the missing gap I would appreciate it. Also another part of the code that is kind of not making sense is the dataTable1.setVar("catalog"); line. Where does the author get 'catalog' from?
    Hope someone can help me out.
    Thanks in advance.
    Surya

    In this line dataTable1.setVar("catalog"); you are making a reference to your value. Inside the datatable, you will refer to the value (a register in the model) as catalog. So you can access all properties of a single register.
    Column1 and column2 are columns in the table.
    It's better to you to see first a more simple example of a datatable.
    http://www.laliluna.de/first-java-server-faces-tutorial.html

  • How to filter the data displayed in a datatable

    Is there a way to populate a datatable so that the data displays in a column only when it is different than the previous rows. For example if I have a List of InventoryItems that have properties State, WHouse, Widget, Count.
    And I want to display them something like this:
        GA    WH1    Widg1      255
                     Widg2      566
                     Widg3      999
              WH2    Widg1      100
                     Widg4       55
        FL    WH5    Widg1      687
              WH6    Widg5      566I hope the formatting comes out correct. The GA & FL should be in the first column. WHX in the second, WidgX in the third, and the count in the fourth.
    I hope someone has an idea how I can achieve this effect.
    Thanks

    Yes, binding to the rendered property the way you suggested should do the trick.
    FYI, here's an example that illustrates how the <if> component in JSFTemplating works:
    <foreach key="key" list={"A" "B" "C"}>
        <!if !(#{key} = B)>
            <staticText value="Not B, it's '<b>#{key}</b>'</br>" />
        </if>
    </foreach>If you cut / paste that code into a file called test.jsf and run it in a JSFTemplating enabled application (follow the directions on the www site to run the demo app, drop it in that app), it will show values not equal to 'B" (A and C). FYI (#2): the <staticText> component above has a short cut syntax, so it could also be written:
    <foreach key="key" list={"A" "B" "C"}>
        <!if !(#{key} = B)>
            "Not B, it's '<b>#{key}</b>'</br>
        </if>
    </foreach>FYI (#3): You can use any #{} you want in the <if> condition and can form complex boolean equations.
    Good luck!
    Ken Paulsen
    https://jsftemplating.dev.java.net

  • Hibernate datatable component

    Hi,
    I'm building a component to display a datatable from a hibernate select statement. I want to have pagination and a sorting mechanism.
    The problem now is that my component goes two times to the database. First time when he restores my view (lifecycle 1) and secondly when he creates my response (lifecycle 6).
    I'm sure somebody was before me to create a component like this, but I can't find docs on the internet. Does somebody know where I can find a component like this. Note, I don't want to use spring, keep it clean only JSF and hibernate.
    Thx in adv,
    Pieter

    hi;
    actually you should not make a db connection in restoreview Phase, instead restore your datasource from the viewstate
    in your components encoding phase you should make db queries.
    please take look to the following code.
    @Override
    public Object saveState(FacesContext context) {
    Object values[] = new Object[2];
    values[0] = super.saveState(context);
    values[1] = label;
    return ((Object) (values));
    @Override
    public void restoreState(FacesContext context, Object state) {
    Object values[] = (Object[])state;
    super.restoreState(context, values[0]);
    label = (String)values[1];
    http://asahin.net

  • Label display issue in Tree component when it is having vertical scrollbar

    I am using tree component as dropdown factory for combo box. When i open dropdown, it doesn't have vertical scrollbar and all the root nodes are getting displayed correctly(in closed mode). Now if i try to open any node, i am getting vertical scrollbar as the child nodes are more. Now the problem is if scroll down, some of the nodes(labels) are not getting displayed but i am able to see the icon. If i keep on scrolling bottom to top and top to bottom, some of the nodes are showing labels and some are not(It is inconsistant).
    I have not used any custom item renderer for tree control. I used my custom dataDescriptor which i have implemented from ITreeDataDescriptor. Also I tried extending DefalutDataDescriptor, but no luck.

    Does it work if the tree is not in a combobox?

  • Displaying resultset one record at a time

    This is a rather long question, but I have never done any projects like this before with Java.
    I have an application in which users can view each record within a range of values one at a time. I have created a recordset that is sorted by one column in the resultset. What is the best way to display each record using forward/back buttons to "flip" through each record? How would I keep track of which record in the set I am actually displaying so I can move to either the next or previous depending on which button the user selects? Another problem I have is whether a particular button should be disabled?
    Thanks in advance,
    Chris

    Try this link
    http://www.theserverside.com/resources/article.jsp?l=DataListHandler
    Select the Read PDF here link and it will download the PDF for you to read.
    It's a pattern for the sort of problem that you describe. It comes complete with source code that you could use.
    If you wish you can contact me via e-mail and I'll email you a working example.
    Dave

  • Jsf datatable inside datatable component rendering problem.

    I am creating an online survey application using JSF with IceFaces component library. The survey can have any number of questions. Each question can be any one of the types checkbox, radio button, etc with multiple options.
    For this, I am using a datatable to dynamically add a question to the survey. Inside that datatable, I am using another datatable to add option to the survey.
    Now the problem is, if I keep on click on add question button, in the outer data table, question is being added without any issue. Once I click on inner data table to add a option to any of the added questions, I am able to add. But after that, if I click again on add question button, it is not working.
    This is my xhtml code:
    <ice:dataTable id="icePnlQuestionAdd" var="questAdd" value="#{createSurveyManagedBean.surveyQuestionList}">
    <ice:column>
    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th><ice:outputText value="Question English" style="white-space: nowrap;" /></th>                                        
    <td colspan="15">                              
    <ice:inputText id="QuestionEn" style="width:485px;" value="#{questAdd.questionEn}" />
    </td>
    </tr>
    <tr>
    <ice:dataTable id="icePnlOptionAdd" var="optionAdd" value="#{questAdd.surveyQuestionOptionList}">                               <ice:column>
    <th><ice:outputText value="Option " /></th>
    <td><ice:inputText id="OptionEn" value="#{optionAdd.optionEn}" /></td>
    </ice:column>
    </ice:dataTable>
    </tr>
    </table>
    </ice:column>
    </ice:dataTable>
    This is the add question method:
    public String addQuestion() {
    SurveyDTO addSurveyQuestionDTO = new SurveyDTO();          
    questionNum = surveyQuestionList.size();          
    addSurveyQuestionDTO.setQuestionNum(questionNum);
    surveyQuestionList.add(addSurveyQuestionDTO);
    return "createSurvey";
    This is the add option method:
    public String addOption() {
    FacesContext context = FacesContext.getCurrentInstance();          
    if (context.getExternalContext().getRequestParameterMap().get("questionNum") != null) {
    String questionNum = (String) context.getExternalContext().getRequestParameterMap().get("questionNum");
    int selectedQuestionNum = Integer.valueOf(questionNum);                    
    SurveyQuestionOptionDTO surveyQuestionOptionDTO = new SurveyQuestionOptionDTO();
    surveyQuestionList.get(selectedQuestionNum).getSurveyQuestionOptionList().add(surveyQuestionOptionDTO);
    return "createSurvey";
    }

    Bind the h:datatable in the jsp to UIDataTable component in your java code. Then when the action method is invoked, use DataTable.getWrappedObject() to get the model. Cast the model to whatever your type is (List, Array...) and then iterate through the model to process individual rows.

  • Need help displaying images with List component for Flash CS4 (ActionScript 3.0)

    Hi folks:
    I am an inexperienced user of Flash CS4 Pro (v10.0.2). I am attempting to use the List component with ActionScript 3.0 to make a different image display when a user clicks each item in a list.
    I did find a tutorial that showed me how to make different text display using a dynamic text box and the following ActionScript:
    MyList.addEventListener(Event.CHANGE, ShowSelectedItem);
    function ShowSelectedItem(event:Event):void {
        ListText.text=MyList.selectedItem.data;
    ...where My List is the instance of the List component and ListText is the dynamix text box. In this case, the user clicks an item in the list, defined by the label value in the dataProvider parameter of the List component, and text displays as defined in the data value in the dataProvider parameter.
    However, as I mentioned to start, what I really want to do is make images display instead of text. Can anyone provide me the steps to do this?
    I appreciate your help (in advance)!!
    Cindy

    Hi...thanks for responding! I was planning on using images from the Library, but if there is a better way to do it, I'm open. So far, I just have text in the data property. This is part of my problem. I don't know what I need to put in the data value for an image to display. Do I just put the image file name and Flash will know to pull it from the Library? Do I need to place the images on the stage on different frames? I apologize for the "stupid user" questions, but as you can tell, I'm a newbie.
    Appreciate your patience and any help you can offer!
    Cindy

  • Displaying Images In Form Component

    Hi
    How do I display an employee image in a form Componet, if it is located in file server??
    and how do display an employee image in form component
    if it is saved in the Databse ??
    Many Thanks
    null

    Walid,
    If you want to display an image in a form it should be "physically" uploaded to the table on which your form is based. The only supported datatypes now are BLOB and ORDIMAGE (interMedia image).
    Thanks,
    Dmitry

Maybe you are looking for

  • Look up in Dictionary.app

    Is there any way to look up a word directly in Dictionary.app? Control clicking a selected word, choosing "Look up..." brings up the definition(s) in a pop up window. Then clicking on "Dictionary" takes you to the Dictionary application... But I pref

  • Can I use one Adobe ID for two separate CC Teams?

    I recently got a new job, and am still doing freelance work for my past employer, who will continue to keep me as a seat in their CC membership (CC for Teams).  At my new job, they are in the process of switching over to CC.  Will I have to obtain an

  • Full Outer Join Help Needed

    Hi All, I am new to crystal and my sql. l have 2 command objects in that i have a common column pos_no.Now i need to apply Fullouterjoin between pos_no,but in crystal we don,t have that option. So i saw some threads that we need to apply leftouterjoi

  • Battery not saving settings in Logic

    Anyone else having trouble saving settings in Battery? Here's an example of the problem: 1. Open Session1 in Logic (X or 9), open an instance of Battery, open a kit (e.g. 909 Detailed Kit), save, close. 2. Open Session2 in Logic (X or 9), open an ins

  • Interactive Form Issues

    Hi, In general my application is as following with tow Views: 1- After the use enter the search criteria in View1 and click Preview Button. 2- View2 open PDF file. 3- In View2 I have a Interactive form to open PDF. My Issues are: 1- After I go and ru