0 Replies Latest reply: Jul 7, 2007 9:16 PM by 807605 RSS

    CachedRowSet SQL variable

    807605
      Could use a kind word and a cup o' java here....

      I am attempting to add code to a SessionBean.java routine.

      From looking thru the docs, I believe that this is the point where a component (table) that is binded to a datasource

      (database table) rowset is retrieved from the table.

      Below, in the void _init() there are three ways in which I have tried to set the CachedRowSet setCommand string to retrieve a

      rowset based on the value in a variable (retnumber).

      In testing these ways, you can see that I have initialized the value of int retnumber = 5.

      (in the actual app, the value of retnumber is set by the random number method and used)

      At this point I do not believe that retnumber has no value (except null, maybe)
      because in the one instances where I supplied the variable name, the .jsp page rendered properly, except in the table column

      it informs me that "no items found". Hence retnumber has no value or I am not structuring the SQL query correctly

      Because in the instance that I supply an actual value (1,7,39 or whatever) a rowset record is returned.

      And in the third instance it returned all records in the table.

      My question would be then....

      Am I structuring the query correctly in the SQL string

      thnx for any input and help.

      regards




      public class SessionBean1 extends AbstractSessionBean {
      // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
      private int __placeholder;

      /**
      * <p>Automatically managed component initialization. <strong>WARNING:</strong>
      * This method is automatically generated, so any user-specified code inserted
      * here is subject to being replaced.</p>
      */
      private void _init() throws Exception {

      int retnumber=5;

      tbl_booklistRowSet.setDataSourceName("java:comp/env/jdbc/mysql_bibles3306");
      tbl_booklistRowSet.setCommand("SELECT ALL tbl_booklist.book_num, \n tbl_booklist.book_name \nFROM

      tbl_booklist\nORDER BY tbl_booklist.book_num ASC ");
      tbl_booklistRowSet.setTableName("tbl_booklist");
      tbl_itdontaddupRowSet.setDataSourceName("java:comp/env/jdbc/mysql_bibles3306");

      ********
      tbl_itdontaddupRowSet.setCommand("SELECT ALL tbl_itdontaddup.ID, \n tbl_itdontaddup.Hype, \n

      tbl_itdontaddup.Fact, \n tbl_itdontaddup.Dev_Title, \n

      tbl_itdontaddup.Dev_Verse, \n tbl_itdontaddup.Dev_Text, \n tbl_itdontaddup.Note_Text, \n

      tbl_itdontaddup.Note_Ref, \n tbl_itdontaddup.Headline, \n

      tbl_itdontaddup.Article \nFROM tbl_itdontaddup\nWHERE tbl_itdontaddup.ID = 'retnumber' ");


      ********
      //tbl_itdontaddupRowSet.setCommand("SELECT ALL tbl_itdontaddup.ID, \n tbl_itdontaddup.Hype, \n

      tbl_itdontaddup.Fact, \n tbl_itdontaddup.Dev_Title, \n

      tbl_itdontaddup.Dev_Verse, \n tbl_itdontaddup.Dev_Text, \n tbl_itdontaddup.Note_Text, \n

      tbl_itdontaddup.Note_Ref, \n tbl_itdontaddup.Headline, \n

      tbl_itdontaddup.Article \nFROM tbl_itdontaddup\nWHERE tbl_itdontaddup.ID = 1 ");

      ********
      //tbl_itdontaddupRowSet.setCommand("SELECT ALL tbl_itdontaddup.ID, \n tbl_itdontaddup.Hype, \n

      tbl_itdontaddup.Fact, \n tbl_itdontaddup.Dev_Title, \n

      tbl_itdontaddup.Dev_Verse, \n tbl_itdontaddup.Dev_Text, \n tbl_itdontaddup.Note_Text, \n

      tbl_itdontaddup.Note_Ref, \n tbl_itdontaddup.Headline, \n

      tbl_itdontaddup.Article \nFROM tbl_itdontaddup ");

      tbl_itdontaddupRowSet.setTableName("tbl_itdontaddup");
      }