Use an SQL Query in a backing bean

hi,
I like to know how to run an SQL query in a backing bean method, this being the code I tried , his goal is to fill the field "cin" with data coming from my database, here is the Code:
public String cb2_action() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("CreateInsert");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
return null;
DCIteratorBinding dciter =(DCIteratorBinding) bindings.get("PersonneView1Iterator");
Row row=dciter.getCurrentRow();
Statement stmt = this.getDBTransaction().createStatement(1);
try {
ResultSet rs = stmt.executeQuery("select max(cin) from personne");
while( rs.next() ){
row.setAttribute("cin", rs.getInt(1)+1);
} catch (SQLException ex) {
ex.printStackTrace();
return "go";
at run time it give an error at this line : Statement stmt = this.getDBTransaction().createStatement(1);
please check and correct me
thanks in advance

Hi,
Initially I would like to say that this should not be used if you are trying to get a PrimaryKey as it would cause serious concurrency issues.
For example lets say that you want whenever you create a new Employee to set his DepartmentId equal to the max department.
We could create a readOnly VO (lets name it MaxDepartmentId) with a query that returns the max departmentId:
select max(Department_Id) as maxDep from DepartmentsAfter that we need to add the MaxDepartmentId VO as a ViewAccessor in our Employees Vo,
override the create() method in the EmployeesRowImpl and add some code like this:
public class EmployeesRowImpl extends ViewRowImpl {
    @Override
    protected void create(AttributeList attributeList) {
        Row r=getMaxDepartmentId().first();
        if(r!=null){
             Number max=(Number)r.getAttribute("Maxdep");
             attributeList.setAttribute("DepartmentId", max);
        super.create(attributeList);
}That's all.
If you run this you will see that when you create a new employee it has a default value.
Gabriel.

Similar Messages

  • Using a SQL Query in an Alert and Matching a String

    I've created an alert in 12.0.4 using a SQL Query and the field that I'm trying to match is a string.  Originally the query returned multiple rows but when the alert still didn't fire, I modified the query WHERE clause to return only one row:
    NAME                                RESPONSE
    Are area lights working?            No
    My expression in the metric is RESPONSE.  In the Monitor I'm matching a string equal to No.  (Do I need double quotes around the matchvalue?  Single quotes?  No quotes?)  The metric is in the 15min scan group, the role is xMII Developers and I'm in that role. The monitor alert string is ' =  '.  Both metric and monitor are active and I've subscribed to the monitor.  Other alerts in the 15min scan group (all based on tag queries) are firing off properly.
    Why is nothing showing up in the Alert Log?
    David Macindoe

    David,
    Did you figure out the answer?  If not, I will try to find someone to address your question.
    Mike

  • XML Generation using a sql query in an efficient way -Help needed urgently

    Hi
    I am facing the following issue while generating xml using an sql query. I get the below given table using a query.
         CODE      ID      MARK
    ==================================
    1 4 2331 809
    2 4 1772 802
    3 4 2331 845
    4 5 2331 804
    5 5 2331 800
    6 5 2210 801
    I need to generate the below given xml using a query
    <data>
    <CODE>4</CODE>
    <IDS>
    <ID>2331</ID>
    <ID>1772</ID>
    </IDS>
    <MARKS>
    <MARK>809</MARK>
    <MARK>802</MARK>
    <MARK>845</MARK>
    </MARKS>
    </data>
    <data>
    <CODE>5</CODE>
    <IDS>
    <ID>2331</ID>
    <ID>2210</ID>
    </IDS>
    <MARKS>
    <MARK>804</MARK>
    <MARK>800</MARK>
    <MARK>801</MARK>
    </MARKS>
    </data>
    Can anyone help me with some idea to generate the above given CLOB message

    not sure if this is the right way to do it but
    /* Formatted on 10/12/2011 12:52:28 PM (QP5 v5.149.1003.31008) */
    WITH data AS (SELECT 4 code, 2331 id, 809 mark FROM DUAL
                  UNION
                  SELECT 4, 1772, 802 FROM DUAL
                  UNION
                  SELECT 4, 2331, 845 FROM DUAL
                  UNION
                  SELECT 5, 2331, 804 FROM DUAL
                  UNION
                  SELECT 5, 2331, 800 FROM DUAL
                  UNION
                  SELECT 5, 2210, 801 FROM DUAL)
    SELECT TO_CLOB (
                 '<DATA>'
              || listagg (xml, '</DATA><DATA>') WITHIN GROUP (ORDER BY xml)
              || '</DATA>')
              xml
      FROM (  SELECT    '<CODE>'
                     || code
                     || '</CODE><IDS><ID>'
                     || LISTAGG (id, '</ID><ID>') WITHIN GROUP (ORDER BY id)
                     || '</ID><IDS><MARKS><MARK>'
                     || LISTAGG (mark, '</MARK><MARK>') WITHIN GROUP (ORDER BY id)
                     || '</MARK></MARKS>'
                        xml
                FROM data
            GROUP BY code)

  • Can we use Data Pump to export data, using a SQL query, doing a join

    Folks,
    I have a quick question.
    Using Oracle 10g R2 on Solaris 10.
    Can Data Pump be used to export data, using a SQL query which is doing a join between 3 tables ?
    Thanks,
    Ashish

    Hello,
    No , this is from expdp help=Y
    QUERY                 Predicate clause used to export a subset of a table.
    Regards

  • How to use this sql query in oracle?

    Hi all,
    i am using one sql query that is
    SELECT @ToDate = '2012-10-03 00:00:00.000'
    select @BetweenDate = DATEADD(MM,-1,@ToDate)
    select @FromDate = DATEADD(m,DATEDIFF(m,0,@BetweenDate),0)
    SELECT @ToDate = DATEADD(month, ((YEAR(@BetweenDate) - 1900) * 12) + MONTH(@BetweenDate), -1)
    so @todate value is = '2012-10-03 00:00:00.000'
    so in @betweendate value will come 1 month before like '2012-09-03 00:00:00.000'
    again in @fromdate value will come like that '2012-09-01 00:00:00.000' means first date of @betweendate
    and again @todate value will come like that '2012-09-30 00:00:00.000' means last date of @betweendate
    it's happening in sql and i have to use same logic in oracle also.
    how to use it??
    thanks

    declare
    todate date:= to_date('2012-10-03 00:00:00','yyyy-mm-dd hh:mi:ss');
    betwendate date := add_months(todate,-1);
    for datediff / additions you can direct subtract/add two different date variables
    like
    datediff = betweendate -todate
    dateadd := todate+1;

  • How to call the Reset of af:query in a backing bean .

    Hi, Could some one help me to call the Reset function of af;query by a backing bean. Since i need to refresh the LOV's in the search panel, i need to call the reset operation in the custom code. . thanks.

    Here is the test case Frank.
    I'm having a af:query component and search fields are populated by choice-list LOV .... The VO populating the lov attribute is , is set with auto refresh . In case of new records in the DB, i want the lovs at the search fields of af:query getting updated automatically. Right now , if i click the Reset button then the lovs are getting updated. So i wanted to do the reset programmaticaly to update the lovs of af:query.

  • I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work

    Hi,
    I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work
    (fault number -2147217900)
    I want to search for a value in a ms access table , if it exist i want to update it, if not i want to insert a new row.
    Working with LabView 7.1, database con. toolset.
    Who can HELP?
    Thanks a lot
    Marco

    Hello,
    I think that If exist is not a standar SQL command (I know it exists I think in Oracle and SQL server), MS access doesn't support it, so I think the best way to do it is first make a Select and then either an Update or an insert, sorry...
    Paulo

  • Using multiple sql query

    Im writing a jsp that pulls data from the database and loads it into dropdown-list looks like this:
    <select name="Source">
    <%
    conn = DriverManager.getConnection(url, username, password);
    Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = stmt.executeQuery("SELECT BBCourseID(Sroffer.SrofferID)course_name, SrofferSchedule_Faculty.FacultyID AS FacultyID FROM SrofferSchedule_Faculty srofs JOIN SrofferScheduleID sros ON srofs.SrofferScheduleID= sro.SrofferScheduleID JOIN Sroffer sro ON sro.SrofferID= sros.SrofferID WHERE srofs.FacultyID=IDnumber");
    rs.beforeFirst();
    while (rs.next()) {%>
    <option value="<%=courseid=rs.getString("BBCourseID")%>"><%=courseid%> <%=rs.getString("course_name")%></option>
    <%}
    %>
    </select>
    Problem is, I have to pull the FacultyID from cams using this sql query
    ("SELECT FacultyID FROM FacultyPortal WHERE PortalAlias="") berfore i can run the query above. Don't know how to do this in a jsp
    Edited by: JohnsonJ on Mar 26, 2009 5:53 PM

    You know how to get a connection and how to execute a query and how to process the resultset - so what's standing in your way of doing that for the faculty ID?
    Isn't there a join you can do to get that in one query?
    And finally - you really shouldn't do this in a JSP, use a servlet to package the result up in some Java Collection and process it with JSTL tags.

  • How to call a query from the backing bean ?

    Hi all,
    Another question for you guys :
    I made a jspx page with an input form and a submit button.
    When I click the submit button, the action my_action in my backing bean is executed.
    This is the code :
    public BindingContainer getBindings() {
    return BindingContext.getCurrent().getCurrentBindingsEntry();
    public String my_action() {
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("EmployeesView");
    Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty()) {
    return null;
    I hoped that the query 'EmployeesView' was executed in this way, but I get the following exception :
    java.lang.ClassCastException: oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding cannot be cast to oracle.binding.OperationBinding
    So how should I execute the query EmployeesView ?
    Second part of the question : What if I typed the name an employee in my form, and I want to
    execute a query that selects all the Employees with that name ?
    How do I make a query with a variable as input in the WHERE clause ?
    Thanks in advance.
    Edited by: Facehugger on 7-apr-2010 11:15

    I'm still trying all the stuff you guys says, but still no result.
    This is my backing bean :
    +// the button action+
    +public String my_action()  {+ 
    +// get the selected rows from the multiselect table and store the objectid's in an String array+
    RowKeySet rks = graph_table.getSelectedRowKeys();
    Iterator itr = rks.iterator();
    Object key;
    int nbr_objects = 0 , i = 0;
    if (rks.size()>0)  nbr_objects = rks.size();
    +String[] objectid = new String[nbr_objects];+
    while(itr.hasNext())
    +{+
    key = itr.next();
    graph_table.setRowKey(key);
    Object o = graph_table.getRowData();
    JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding) o;
    Row row = rowData.getRow();
    +objectid[i] = row.getAttribute("Objectid").toString();+
    i+;+
    +}+
    +// now get all the x and y values for these objectid's from the database out of the table history.+
    BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
    for (int j=0 ; j<nbr_objects; j+){+
    +// get X and Y values for object number j+
    DataPoints history = new DataPoints();
    OperationBinding operationBinding = bc.getOperationBinding("retrieveHistory");   ===> operationBinding stays NULL ???+
    +operationBinding.getParamsMap().put("OBJECTID", objectid[j]);+
    Object retVal = operationBinding.execute();
    +// ==> retVal should contain a List of all X and Y values for the provided objectid.+
    +// while (retVal has values)+
    +// {+
    +// List_of_x_values.add(retVal.valueX);+
    +// List_of_y_values.add(retVal.valueY);+
    +// }+
    history.add(List_of_x_values);
    history.add(List_of_y_values):
    +// call the soap method to do some calculations+
    methodname.forecast(history);
    +}+
    +}+
    In my application module :
    public void retrieveHistory(String objectid) {
    getHistory().setWhereClause("OBJECTID = '" + objectid + "'");
    System.out.println("current query : "+getHistory().getQuery());
    getHistory().executeQuery();
    public ViewObjectImpl getHistory() {+
    return (ViewObjectImpl)findViewObject("History");+
    The query for the VO History : SELECT * FROM HISTORY
    Please anyone ?
    Edited by: Facehugger on 9-apr-2010 14:19

  • Is there a way to consolidate calculations used in SQL Query Data Sets?

    I am building SQL Query Data Sets against multiple DB Views which all have different date formats. I have the date parameter working well, but want to consolidate the changes that I have to do to it especially for the quarter. For example the SQL against a monthly view would use "where year_month > to_char(:ST_DATE, 'YYYY-MM')" which is not too hard, but to make that work for the quarterly view I need several concats and a decode to get a "> '2012-Q2'". I would like not to have to do this within every where clause. I had put this into a global element hoping to use that in a filter for the data set, but the filter does not have access to global elements only parameters.
    Is there any way to refer to a calculated global element from the data set to do this? I am using Layout Templates, so even if I wanted to I could not do the condition within the template.
         Thanks,
         Rick

    Change the following line to include the red coloured parts
    <div class="MasterColumn" spry:repeat="ds4" spry:setrow="ds4" spry:hover="MasterColumnHover" spry:select="MasterColumnSelected">
      <span>{Dsp_#}</span><span>{Dsp_WkDay}</span><span>{Dsp_Event}</span>
    </div>
    The add the following style rule to your document:
    .MasterColumn span {
        display: inline-block;
    I hope this helps.
    Ben

  • Check the hints used in SQL Query (Parallel, First_Rows)

    Hi,
    I have used above hints in my sql query and found no difference in execution time.
    I just want to know whether the hints are used in my sql are not.
    Could you please let me know where to check for it.
    Thanks in advance

    Can you post the SQL which uses these hints and the execution plan with and without those hints here? Then only community can help you find out if the hints are really used or not.
    Please use code tags to preserve the format of execution plan.
    Edited by: Satish Kandi on Jun 23, 2009 5:37 PM

  • How to create a Folder using a SQL Query?

    Hi
    How can I create a Folder (eg. C:\MyNewFolder) using SQL Query?

    Hi,
    I added some code in order to get the result from the xp_cmdshell command
    This returns null if successfull, if an error occurs returns the error message. May be useful instead of getting an sql error
    Code Snippet
    declare @cmdpath nvarchar(60), @Location nvarchar(100), @message nvarchar(max)
    set @Location = N'C:\Temp\Temp5'
    set @cmdpath = 'MD '+ @Location
    Create table #result
    result nvarchar(255)
    insert into #result (result) exec master.dbo.xp_cmdshell @cmdpath
    select @message = ISNULL(@message + ' - ','') + result from #result where result is not null
    select @message
    drop table #result
    Eralper
    http://www.kodyaz.com

  • SQLEception using Complex SQL Query with Java Studio Creator2 Build(060120)

    I am evaluating Java Studio Creator2 for a WEB base application project that will be making SQL queries to an Oracle Database but I have stumble into a problem using complex SQL queries.
    I am getting an SQLException "org.apache.jasper.JasperException: java.lang.RuntimeException: java.sql.SQLException: [sunm][Oracle JDBC Driver][Oracle]ORA-00923: FROM keyword not found where expected". I looks like it cut my sql.
    The SQL that I am trying to execute is
    Select part_name
    from table1, table2
    where table1.part_nbr = table2.part_nbr
    and table2.row_add_dt = (select max(table3.row_add_dt)
    from table3
    where table3.ser_part_id =table2.ser_part_id)
    This is a valid query that it is using 2 different selects to get a part number.
    If posible, point me to the best solution were I will be able to make complex SQL queries like the one above and bigger.
    Is there any way that I can read an SQL query file instead of inserting the SQL query string into the setCommand()?

    I have read that document looking for some anwsers on how to make this kind of query. If I try the query that I have above in the query editor ,the query editor will cut off from the last select that is between ().
    I beleave, there is a work around using the inner joint or outter join command. I will try them to see If I get the corrent result. If not, then I have to keep on asking for possible solutions.
    Anyway, someone in the Creator Team should take a note in adding something like a special criteria in the Add Query Criteria Box for cases like the one I have. The special criteria will be like using another select/from/where to get some result that will be compare.
    Girish, Are you in the Sun Creator Team?

  • What tag to use to print STRING value from Backing Bean

    Hi;
    I would like to achieve the objective as below:
    Displaying 4 buttons (pagination) in my jsf page:
    1) Go First
    2) Go Previous
    3) Go Forward
    4) Go Last
    <h:commandButton image="images\first(on).gif" type="submit" action="#{alertSetBean.goFirst}"/>
    <h:commandButton image="images\previous(on).gif" type="submit" action="#{alertSetBean.goPrevious}"/>
    <h:commandButton image="images\forward(on).gif" type="submit" action="#{alertSetBean.goForward}"/>
    <h:commandButton image="images\last(on).gif" type="submit" action="#{alertSetBean.goLast}"/>In order to make sense for user, when the page is displaying first set element records, the icon should be disabled for
    -Go First
    -Go Previous
    and same goes to last set element records, icon to disable for
    -Go Forward
    -Go Last
    To disable, i will substitute
    <h:commandButton image="images\forward(on).gif" type="submit" action="#{alertSetBean.goForward}"/>
    with
    <h:graphicImage value="images\previous(off).gif" />
    It looks very messy in jsf page. Therefore, I would like to call a method in Backing Bean, where it will do check pagination by returning the long string as following:
    <h:commandButton image="images\first(on).gif" type="submit" action="#{alertSetBean.goFirst}"/>
    <h:commandButton image="images\previous(on).gif" type="submit" action="#{alertSetBean.goPrevious}"/>
    <h:commandButton image="images\forward(on).gif" type="submit" action="#{alertSetBean.goForward}"/>
    <h:commandButton image="images\last(on).gif" type="submit" action="#{alertSetBean.goLast}"/>Unfortunately, i'm using
    <h:outputLabel
    <h:outputText
    The JSF page DOES NOT render the code, and it print the string instead. Please, I need advise.
    Thanks;
    Yoke Yew

    Hi Balu;
    Before i received your great response, i was in the midst debugging
    Servlet.service() for servlet jsp threw exception
    org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
    with my following JSTL code
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
    <tr>
           <td align="right">            
                </f:verbatim>
                <h:outputLabel value="#{alertSetBean.totalCnt}" styleClass="lbl"></h:outputLabel>
                <h:outputLabel value="  Total  " styleClass="lbl"></h:outputLabel>
              <c:if test="${alertSetBean.pagination == 1}">
                   <h:graphicImage value="images\first(off).gif"/>
                <h:graphicImage value="images\previous(off).gif" />
                <h:commandButton image="images\forward(on).gif" type="submit" action="#{alertSetBean.goForward}"/>
                <h:commandButton image="images\last(on).gif" type="submit" action="#{alertSetBean.goLast}"/>
              </c:if>          
              <c:if test="${alertSetBean.pagination == 2}">
                   <h:commandButton image="images\first(on).gif" type="submit" action="#{alertSetBean.goFirst}"/>
                <h:commandButton image="images\previous(on).gif" type="submit" action="#{alertSetBean.goPrevious}"/>
                <h:commandButton image="images\forward(on).gif" type="submit" action="#{alertSetBean.goForward}"/>
                <h:commandButton image="images\last(on).gif" type="submit" action="#{alertSetBean.goLast}"/>
              </c:if>
                <c:if test="${alertSetBean.pagination == 3}">
                     <h:commandButton image="images\first(on).gif" type="submit" action="#{alertSetBean.goFirst}"/>
                <h:commandButton image="images\previous(on).gif" type="submit" action="#{alertSetBean.goPrevious}"/>
                <h:graphicImage value="images\forward(off).gif"/>
                <h:graphicImage value="images\last(off).gif" />
                </c:if>
                <f:verbatim>
           </td>
      </tr>I hope somebody can point where is my mistake, and i will refer to your previous solution suggested. Thanks in advance.

  • How do I pull SharePoint 2013 list data using a SQL Query

    I have been asked to write a sql query to pull data from a SharePoint 2013  List.it needs to return all the columns
    Basically a Select all from the specific SharePoint list Database
    I do have the  list GUID ID. But not sure  which  SQL Table or Database to look in for list data.. the site and the list is in our main SharePoint site collection.
    the query only needs to be saved in SQL server

    I know it isn't support but sometimes you have to share data with other programs....
     I'm stuck.. I was able to get this far...
    SELECT * FROM dbo.Lists
    where tp_Title ='List Name'
     how do I pull the columns of the list?
    I think I still need the specific list not just the master list dbo....
    those two links do not work for SQL server  and SharePoint 2013

Maybe you are looking for

  • External Monitor Setup Help

    I was wondering if anyone knew a way that I could connect my laptop to another monitor, and then connect the laptop to my Macbook Pro, and use both the laptop's monitor, and the monitor it's connected to, as external monitors. I was also thinking I c

  • Issue while installing Project Controls application in Unifier 10.1

    Hi , I am installing Unifier 10.1 under weblogic 12c. Everything went fine till deployment and logged in as Site Administrator to install the Project Controls application .While trying to install the application , after a certain period of processing

  • Telnet & Ping Problem

    Hello, I have problem in 2950 Switch, i configured a IP address on it, but when i try ping or telnet this switch, switch does not respond to my telnet and ping. But when i check a SH CDP NEIG command on a connected switch, Switch display the switch,

  • PHP variable scope bug in CT

    I have a page where I declare PHP variables which are then used inside an include file. When I try to edit the page in Contribute, I get a notice of "Variable undefined" in the include. This do work in Dreamweaver and it did work in Contribute in oth

  • Error when execute a WDA: termination type: RABAX_STATE

    Hello, I created a WDA that into the event button (on click) call a function DATA val1 TYPE I. DATA val2 TYPE I. DATA val3 TYPE I. val1 = 12. val2 = 13.   CALL FUNCTION 'ZGB_FUNC01'     EXPORTING         VAL_A       = val1         VAL_B       = val2