How to get result of querry independet of a datatype?

Hi All!
I try to write a program, that calls stored procedures in a database independent of a name and arguments list. To get a result of a query I must call one of the functions getInt(), getString() etc. of CallableStatement. I'd like to write a wrap function, for instance getResult(), that get the result independent of the result's type. Has anybody any idea, how I can do it?
Any help will be appreciate.
Regards,
Andrej.

Hi Justin,
Even we have been writing a kind of these generic methods to send a query to database, fetch the Resultset and then populate an ArrayList with the Resultset data.
What do you get out of this ?
-> Less code to maintain
-> Single point of access to datasource
-> JDBC Code reuse
i agree that it might cost some cpu cycles in populating an ArrayList and then doing the casting again. But isn't it worth all the above credits.
An example of such a method is
  public ArrayList execute( String query, ArrayList params )
                throws SQLException {
    Connection con = null; // Database Connection object
    ArrayList rowset = new ArrayList();
    try {
      // Get the Database Connection
      con = connector.getConnection();
      // Use PreparedStatement object to execute the SQL Query
      PreparedStatement pst = con.prepareStatement( query );
      // Bind the columns values from the ArrayList object
      if( params != null ) {
        for( int i = 0; i < params.size(); i++ ) {
          pst.setObject( i + 1, params.get( i ) );
      // Execute the Query to get the ResultSet object
      ResultSet rst = pst.executeQuery();
      // Get column count from ResultSet Metadata
      int colCount = rsmtdt.getColumnCount();  // This may not be the correct syntax
      // Populate ArrayList
      while(rset.next()) {
        ArrayList row = new ArrayList();
     for(int i=1;i<=colCount;i++)
       row.add(rset.getObject(i);
     rowset.add(row);
      // Close the ResultSet and Statement
      rst.close();
      pst.close();
    } catch( SQLException ex ) {
      throw new DBException( "Unable to execute the SQL Query in execute "+
                                 "method of DBBroker class of given status " +
                             " : " + ex.getMessage() );
    } catch( Exception ex ) {
      throw new DBException( "Exception thrown in execute() method of " +
                             "DBBroker class of given status : " +
                              ex.getMessage() );
    } finally {
      try {
        connector.releaseConnection( con ); // Releases the connection
      } catch( DBConException ex ) {
        throw new DBException( "Unable to release the connection of given " +
                               "status : " + ex.getMessage() );
    return rowset;
  }Regards
Elango.

Similar Messages

  • How to get result without single cotes in ''Cast(Multiset( '' Result.

    select cast(multiset(select column_name
    from user_tab_columns
    where table_name = 'DAILY_PRODN_MIS'
    and column_name like '%STOCK%'
    order by column_name) as tab_type) result from dual;
    RESULT
    TAB_TYPE('BAGS_STOCK', 'BLUE_DUST_STOCK', 'CEMENT_STOCK', 'CEMENT_STOCK_33', 'CEMENT_STOCK_43', 'CEMENT_STOCK_53', 'CK_ADJ', 'COAL_IND_D_STOCK', 'COAL_IND_D_STOCK_ADJ', 'COAL_IND_E_STOCK', 'COAL_IND_E_STOCK_ADJ', 'COAL_IND_F_STOCK','OCK_ADJ', 'MTD_COAL_IMP_D_STOCK_ADJ', 'MTD_COAL_IMP_E_STOCK_ADJ', 'MTD_COAL_IND_A_STOCK_ADJ', 'MTD_COAL_IND_B_STOCK_', 'YTD_COAL_IMP_B_STOCK_ADJ', 'YTD_COAL_IMP_C_STOCK_ADJ', 'YTD_COAL_IMP_D_STOCK_ADJ', 'YTD_COAL_IMP_E_STOCK_ADJ')
    How can i get result without single cotes for each column.

    Your query currently returns a collection type (tab_type) whereas it appears you want to return a delimited string.
    There are actually quite a few ways to achieve this - with your own function, with a user-defined aggregate functions (e.g. Tom Kyte's stragg), with the MODEL clause or with CONNECT BY, e.g.
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> SELECT table_name,
      2         SUBSTR (MAX (SYS_CONNECT_BY_PATH (
      3            column_name, ',')), 2) column_names
      4  FROM  (SELECT table_name, column_name,
      5                ROW_NUMBER () OVER (
      6                   PARTITION BY table_name
      7                   ORDER BY column_id) column_order
      8         FROM   user_tab_columns
      9         WHERE  table_name = 'BANK_ACCOUNT'
    10         AND    column_name LIKE '%U%') utc
    11  START WITH column_order = 1
    12  CONNECT BY column_order = PRIOR column_order + 1
    13  AND    table_name = PRIOR table_name
    14  GROUP BY   table_name;
    TABLE_NAME           COLUMN_NAMES
    BANK_ACCOUNT         ACCOUNT_NAME,ACCOUNT_NUMBER
    SQL>

  • How to get result of PING whether TRUE/FALSE and prompt message to user?

    Hi all!!!!
    In Forms 6i, I need to know how to get the result of a ping if the ping is sucessful or not. It should prompt the user whether the connectivity is there or not after the ping statement which is HOST('PING 191.10.10.40'). As of now, when the user select the desired LOV, the corresponding HOST statement is executed. But if the connectivity is not there, the user is left in blank with a hanging situation... So can we not prompt the user if the connection has been failed or not?
    Regards

    Hi,
    You can try this.
    Redirect the output of the ping test to a file. Read the file using TEXT_IO and see if the test is passed. For ex
    host('ping <your_ip> > c:\ping_test.log');Will redirect the ping output to ping_test.log file under c:\ drive.
    Open the file using TEXT_IO and check if you have the text "Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)". If you have, then the host is reachable. Otherwise its not. Depending on that, you can change the flow of your application.
    -Arun

  • How to get result of Select from stored function.

    I need to get result of select from a stored function.
    In the end of my stored function I makes final select (four columns).
    How it can be retrived from function?

    Hi,
    A function can only return one value, but it sounds like you want to return 4 values.
    The one value that you return can be a record, with many columns, such as a ROWTYPE, or a TYPE that you define.
    You can return an XMLTYPE that has whatever elements you want.
    You can write a procedure that has several OUT parameters. (You can have OUT parameters in a function, but a lot of people find that confusing.)
    In very special circumstance, you might consider returning a string that is a delimited list of values, such as '7639,SMITH,,17-DEC-1980'.
    Someoneelse has a good point.
    We could give a better answer if you ask a specific question, like:
    "I have this table ...
    I want a function such that, if I call it with these parameters ... I get ...
    but if I call it like this ... then I get ..."

  • How to get result of MDM validation expression with type warning?

    I need  to get result of MDM validation expression with type WARNING (in automatic execution),
    but - method validationResult.getFailedValidations(..) returns validation if it has type ERROR,
    so all Warnings treated only as success despite it returned false or true.
    My question - how can I get that 'false or true' expression resut for validation.
    thanks

    Hello Vladimir
    By my opinion, hook warning exception isn't make sense because after warning message data will be change(upload).
    Moreover  if you start validation from WF Warning exception doesn't work at all.
    If you want to do some data changes you should use and hook Error exception.
    Regards
    Kanstantsin Chernichenka

  • How to get result

    hi
    i created a java source coded below
    CREATE OR REPLACE JAVA SOURCE
    NAMED "Welcome"
    as import java.lang.*;
    public class Welcome
    public static void main(String s[])
    System.out.println("Welcom to java");
    java created.
    but how to get the result "welcome to java"
    how call or execute Welcome class file.
    thanks any one help
    bye

    Try this:
    CREATE OR REPLACE JAVA SOURCE NAMED Welcome
    as
    import java.lang.*;
    class Welcome
      public static void main(String s[])
        System.out.println("Welcome to java");
    CREATE OR REPLACE PROCEDURE welcome
    AS LANGUAGE JAVA NAME 'Welcome.main(java.lang.String[])'; 
    set serveroutput on
    call dbms_java.set_output(2000);
    exec welcome;

  • How to get Result Count Content By Search Webpart (ContentBySearchWebPart)?

    I'm writing a webpart that extends the out of the box ContentBySearchWebPart.
    Does any one know how to get the search result count from this webpart?
    I did not find any property?

    Hi 
    Thanks but you are referring to the "Search Webpart". I am referring to the "Content Search" or often called "Content by Search" which is different. It's the one under Content Rollup.
    Although very similar they're not - Content Search WP doesn't have that property.
    What I am really after is to hide the whole webpart if there are no results coming back. I tried to figure it out and even write a jQuery that would search for the text "There are no results" message which comes from the webpart when result count=0
    and hide the parent webpart that way. There will be a short flash once the page loads rendering the webpart for a split second and then disappear by jQuery - which is not great UI experience.
    There is this property: "ShouldHideControlWhenEmpty" but it doesn't do anything when there are no results. The webpart is still visible. Webpart has a the Title and the Border around it so when there are no results the title and the border show
    up with no results. Like I said I want to hide the whole thing in that case.
    So I thought I could extend the OOTB ContentBySearchWebPart and get a hold of some kind property that would get me the result count. If the results count is 0 simply I would hide the webpart server side.
    Thoughts?

  • How to get result after click alert view by itms-services://?action=download

    hi,
    is any possible to get result after click alert view by using [[UIApplication sharedApplication] openURL:@"itms-services://?action=download-manifest&url...
    when i close app, the alert view ([[UIApplication sharedApplication] openURL) is aleady exist, is it not uialertview?, i can't find any alert view by
    for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows])   {
            if ([[keyboardWindow description] hasPrefix:@"<UIALERT"] == YES) {
                isExists = YES;
    any help, thanks.

    I have the MS-6968 device and i want to use driver 1.4.x or 3.0.x. I found the driver 1.4.2.10 but i cannot find any WIDCOMMSecurity code.
    So, can anyone give me a link for BTWPatcher.exe???
    It cannot be found here (Jon's Bluetooth ) anymore.
    Thanks

  • How to get result set

    Hi all,
    Please tell me how to get the below required out put.
    this is my table and data
    with t as (select 11 plcy,1 nm from dual union all
    select 11 plcy,2 nm from dual union all
    select 11 plcy,3 nm from dual union all
    select 11 plcy,5 nm from dual union all
    select 22 plcy,1 nm from dual union all
    select 22 plcy,2 nm from dual union all
    select 22 plcy,3 nm from dual union all
    select 33 plcy,1 nm from dual union all
    select 44 plcy,2 nm from dual union all
    select 55 plcy,4 nm from dual union all
    select 66 plcy,3 nm from dual )
    select * from t
    this my required output.
    from above query required output is below
    plcy      nm
    11      5
    33      1
    44      2
    55      4
    66      3
    if pass nm = 5 then 11
    if i pass nm= 1 then 33
    if i pass nm=2 then 44
    if pass nm = 4 then 55
    if i pass nm =3 thne 66
    it means it has only one value from plcy
    11 5
    33 1
    44 2
    55 4
    66 3
    thanks,

    Something like this:
    SQL > with t as (select 11 plcy,1 nm from dual union all
      2             select 11 plcy,2 nm from dual union all
      3             select 11 plcy,3 nm from dual union all
      4             select 11 plcy,5 nm from dual union all
      5             select 22 plcy,1 nm from dual union all
      6             select 22 plcy,2 nm from dual union all
      7             select 22 plcy,3 nm from dual union all
      8             select 33 plcy,1 nm from dual union all
      9             select 44 plcy,2 nm from dual union all
    10             select 55 plcy,4 nm from dual union all
    11             select 66 plcy,3 nm from dual
    12  )
    13  SELECT     MAX(plcy) plcy
    14  ,  NM
    15  FROM       t
    16  GROUP BY NM
    17  ORDER BY PLCY
    18  /
          PLCY         NM
            11          5
            33          1
            44          2
            55          4
            66          3

  • SUBMIT RFGLBALANCE WITH selection criteria, then How to get resulted itab?

    Hi Experts,
    Am looking to develop a similar report which is doing by SAP at detail/item level, but am looking to develop a SUMMARY level.
    SAP report is = FS10N (bhind prog. is RFGLBALANCE / RFGLITEMS )
    my_alv = shuld show only TOTALS / SUMMARY line
    Almost the selection screen is same in both cases.
    So, I wanna to use the same prog. by using SUBMIT from my_alv_report.
    So, when I use
    SUBMIT RFGLBALANCE
      WITH ..........................
      WITH ........................
    AND RETURN.
    then, my_alv_report control goes to RFGLBALANCE prog. there my input is processed and the output internal table is populating in RFGLBALANCE.............so, now, I wanna to get / fetch / pull this populated internal table into my_alv_repor and there by using the same for my alv display.
    ( I know that, if both r Z prog.s/ Z_BAPIs, then, I can use EXPORT & IMPORT )
    So, pls. let me know that,
    Is it possible ?
    If so, How to get it done?
    SUBMIT Syntax pls.
    thanq

    thanq.
    so, then, Can I use like, *INCLUDE RFGLBALANCE*(Standard Prog.) in my_alv_report, I mean, like
    report my_alv_report message-id Z1.
    INCLUDE RFGLBALANCE.
    own_Logic.
    thanq

  • How to get result of select query from  oracle  in VC

    Dear All ,
    I have a application in oracle which insert the data in the oracle database table.
    Now i want to show all the data that has been inserted into the database table in my VC application but i don't know how to handle select query in VC.
    Regards
    Krishan

    Hi Goivndu
    Thanks for your reply .
    I know all those things.
    I have created the system & alias  for my backend oracle system.
    I can also see all the stored procedure that are there in my oracle system.
    I just want to know how to write a select query in a stored procedure .
    you can insert data , Update data through oracle procedure but i don't think there is any way to get the result of select query in stored procedure .
    If you know any way to do that please do let me know .
    Regards
    Krishan

  • How to get results of search help window?

    Hi, experts,
    I have a question here.
    For a field vendor id there is pre-defined search help, with which the detailed information of vendor inclusive the vendor id will be returned. But it will only fill this vendor id field. other information in the result like vendor name will be lost. I still need this information for other fields. And I hope to get other fields filled with the info in the results.
    How can I get the complete info in the result delivered by search help window?
    Can anybody help?
    Best regards,
    Fan

    In short you need to fill the other fields on the screen using the same search help.
    for that read this thread, Thomas nicely explained the same with an example
    Re: Help On Search Help !!!!!
    Abhi

  • How to get result from another JSP file?

    I have to write a jsp (my.jsp) to get information from another jsp file (other.jsp).
    The other.jsp return integer value (0 / 1) so that user can tell if certain service is available or not. And in my.jsp I need to collect such result and other information from a text file to make up of a XML string.
    How can I call other.jsp to get the result? Thanks a lot.

    Hi, I think I didn't describe the problem clearly
    enough. In fact, there is a JSP file, and if our
    database is currently connected, the JSP will return
    value 1, otherwise, it will return 0. My java program
    need to get that result, and then form an XML string,
    and send the string back to the client. I'm just
    wonder how can I write such a program to read result
    from JSP file. Thanks a lot.Why is this function implemented as a JSP file? It should be implemented as a bean. It would be simple to get the information you require from that bean.

  • How to get result of HTTPService within a function?

    Hello all,
    I'm trying to call an HTTPService's send() and get the
    resulting data from within a function, and assigning it locally.
    Specifically, this is what I want:
    private function getData():void {
    myRPC.send();
    //How do I set the result of myRPC.send to a variable here?
    // Neither myRPC.send().result, nor myRPC.lastResult works! I
    get null both times!
    // But if I set myRPC.result to a separate function that
    handles an event, I get the correct data...but not what I want.
    var myObject:Object = ???? myRPC.???
    <mx:HTTPService result="???" fault="???" id="myRPC"
    method="GET" resultFormat="e4x" url="someurl" useProxy="false">
    <mx:request xmlns="">
    <somedata>hi</somedata>
    </mx:request>
    </mx:HTTPService>
    I am also not sure what to put in 'result' and 'fault' since
    I don't want the result/fault to be passed to another
    function...could anyone explain this please? Thanks!

    "Hamshmam" <[email protected]> wrote in
    message
    news:g70olu$jcd$[email protected]..
    > Hi Greg,
    >
    > While this is not what I am looking for, thanks for your
    response.
    >
    > I am familiar with traditional HTTPService requests and
    passing the
    > resulting
    > event to a function handle directly and then modifying
    the object from
    > there.
    > However, as I described in my earlier post, I'm looking
    for a way to get
    > the
    > resulting event of the HTTPService.send() within a
    different function.
    >
    > I am doing this because if I have another function
    dependent on the
    > HTTPService.send()'s data, I cannot simply call the
    HTTPService.send()
    > from
    > within that function and update a class private var with
    the data, which I
    > access from the wrapping function. This is because the
    HTTPService is by
    > nature
    > asynchronous, so it is possible that the class private
    var will remain
    > null
    > while further lines of code are executed, all the while
    the HTTPService is
    > interacting with the server concurrently.
    >
    > I hope it is clear now why I need to assign the result
    of a HTTPService
    > result
    > directly within a function, if you or anyone else could
    shed some light on
    > that, I would appreciate it! Thanks for your response.
    http://www.johnwilger.com/2007/03/future-value-pattern-in-actionscript-3.html

  • How to get result of 2nd value based on first characteristics value

    Hello All,
    Please see the screenshot and let me know how can i achieve the Desired Result:
    Objective :
    Show only those values which are available in first Column i.e. after Date.
    Thanks in advance
    MD

    Hi Manna,
    i got it..
    so this is what your output:
                        chocolate  biscuits
    01.01.2014  100             100
    02.02.2014   0                50
    on a particular day, if the chocolate has the value, then only display that particular row?
    If so, you can try with RKF restricted with chocolate, and apply the condition on this RKF.
    plz try once and let us know.  also i guess this works when we know the char value beforehand, if it gets change, we need to do something else i guess.
    I  may not correct somewhere. experts can advise further if this doesn't work.
    Regards,
    Sakthi

Maybe you are looking for

  • How could I get the used rates of cpu and main memory

    I want to get the used rates of the cpus and the memeoy?How could I do? I write the code on linux and got them by read the file /proc/meminfo and /proc/loadavg. Is there the similar file under solaris? Further more , under the linux os, I could make

  • CS3 Crashes on "Save As" in Windows XP

    Anyone come accross this and have a solution. I can't use the "Save As" command as CS3 crashes as soon as I try to alter the save destination. Thanks

  • NEF File Preview not available w Nikon D300

    Using Lightroom 1.3, when I attach the Nikon D300, 12 or 14 bit file, the NEF and jpg files do import successfully, but only the jpg files show in preview. The NEF previews are grayed out. Sorry if this topic is addressed. I cannot find anyone with a

  • Extremely slow internet pages take 1 min to load

    hola, my internet on my new MBA 11 is extremely slow both on safari and firefox.....I installed the latest software and it is not the internet provider either...I'm lost and frustrated help me xxx

  • Unable to make a call by iPhone 3

    My friend has a problem with calling at iPhone3g. Whenever he is trying to make a call after 1 sek. On the screen pop up the message that " connection ended" Please help me if You can. I've tired to switch on/off the phone, I on/off airplane mode, I