Lists/collections in JDBC

Hi all,
Does anyone know if it is possible to pass to an Oracle stored procedure a Java defined list/collection/array/vector as an IN parameter?
E.g. an array/list of Strings or a vector of booleans.
I know it is possible to pass an sql.array, but I think it is not possible to define one in the Java code itself.
Thanks in advance,
Daniel Palomo van Es.

CC JDBC Parameters:
Connection:
Format need to be specified as  -   jdbc:oracle:thin:@hostname:port:SID
jdbc: oracle:thin:@(DESCRIPTION =     (ADDRESS_LIST =       (ADDRESS = (PROTOCOL = TCP)(HOST = ntbomsap13)(PORT = 1527))     )     (CONNECT_DATA =       (SID = XI3)       (SERVER = DEDICATED)     )   )
Here in this connection url I have replaced: @hostname: port: SID with the TNSNAMES file content.
Processing Parameters:
1.Query SQL Statement: e.g.- select empid, empname, empage from emp_det where empid>1
2. Update SQL Statement: e.g - update emp_det set flag=2 where flag=1
Regards,
Anurag

Similar Messages

  • Adding to a Collection using JDBC

    I'm trying to add to a Collection via JDBC but have had no luck with getting the ResultSet into the Collection and would be grateful for some pointers in the right direction in the while (rs.next()) block:
    public void getMembers(BwGroup group) throws CalFacadeException {
         Class.forName("com.mysql.jdbc.Driver");
         String url = "jdbc:mysql://localhost/loginlist";
         Connection conn = null;
         Collection<BwPrincipal> ms = new TreeSet<BwPrincipal>();
          try {
             conn = DriverManager.getConnection(url, "user", "pword");
             PreparedStatement ps = conn.prepareStatement("SELECT * FROM list WHERE list='" + group +"'");
             ResultSet rs = ps.executeQuery();
                while (rs.next()) {
                   BwPrincipal = new bp(rs.getString(1));
                   ms = addAll(bp);
               group.setGroupMembers(ms);
               rs.close();
               ps.close();
               } catch (Exception e){
                e.printStackTrace();
               } finally {
             if (conn != null) {
            conn.close();
        }I'm getting errors regarding incompatible types for the BwPrincipal line and addAll being an unfound symbol (though I had thought that it was a method to add to Collections). If I try to call BwPrincipal as BwPrincipal bp = new bp(rs.getString(1)); then the addAll error disappears but the programme cannot see BwPrincipal as a class. I feel as if I'm going around in circles at the moment.

    BaroqueThoughts wrote:
    As you say, I'm trying to call something along the lines of
    ms= rs.getString(1);but get an incompatible string back. The reading that I had done suggested addAll but I've probably misunderstood in trying to get this to work. If I try
    ms.add(rs)then the compiler doesn't like the add method (add cannot be applied to java.sql.ResultSet)Well it can't. Why did you try that, though? To be honest, if you can't figure this out yet, JDBC is probably a step too far at the moment. Re-visit the basics, because you clearly don't understand them yet, and you'll struggle forever if you carry on down this path as-is

  • How to write from a linked list collection to a text file.

    Hi,
    I want to write my data in linked list collection to a text file.
    the following is the code of my linked list. how do i write it
    Iwant the data to be comma separated while writing it to a text file.
    please help.
    class MailList
            public static void main(String args[])
                    LinkedList m1 = new LinkedList();
                    m1.add(new Address("J.W.West", "11 Oak Ave",
                           "Urbana", "IL", "118011"));
                    m1.add(new Address("H.S.sandy", "1 k ve",
                           "Bana", "L", "18011"));
                    m1.add(new Address("K.Satish", "1 104 Clarence Street",
                            "Strathfield", "NSW", "135"));
                    Collections.sort(m1);
                    Iterator itr = m1.iterator();
                    while(itr.hasNext())
                            Object element = itr.next();
                            System.out.println(element + "\n");
    }

    look at the API for FileWriter.
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Demantra Price List Collections

    We are collecting price lists from EBS into Demantra and found that not all items from the EBS Price List are included in the collection and download into Demantra msd_dem_price_list table. For example, for one price list, the EBS Price List contains 4014 distinct items with active prices; however ,after price list collection is run into Demantra, only 3160 distinct items with prices are populated in the msd_dem_price_list table for this series.
    Are there any system constraints that limit the items/pricing records included in the price list collection?
    Thanks
    Edited by: user566845 on Oct 18, 2010 3:10 PM

    Hi Raj,
    Thanks a lot for the reply.
    Actually I was thinking of loading the price at a daily level and at a Item - Location level so I'll have the SALES_DATE, ITEM_CODE, LOCATION_CODE, PRICE colums.
    Let's say that I have the next situation: if one product has price 5 starting with 01.01.2011 till 05.31.2011 and starting with that date the price will be 6. How do I define that in the flat file ?
    1. I insert 2 lines i.e.
    SALES_DATE ITEM_CODE LOCATION_CODE PRICE
    01.01.2011 X Y 5
    05.31.2011 X Y 6
    OR
    2. I insert 1 line for each date starting with 01.01.2011 till 05.31.2011 and so on i.e.
    SALES_DATE ITEM_CODE LOCATION_CODE PRICE
    01.02.2011 X Y 5
    01.03.2011 X Y 5
    01.04.2011 X Y 5
    05.31.2011 X Y 6
    06.01.2011 X Y 6
    06.02.2011 X Y 6
    06.03.2011 X Y 6
    Thak you
    AMC

  • Working with List, Collection or Map

    Hello everyone,
    I have the following situation: I must add some values to a List, Collection or Map, and then retrieve them do put them in a combo box. My doubt is: which of them I should use?
    I wanna add a string working as an index and another working as a description. Like this:
    - "First string", "Hey here's my first string"
    - "String 2", "number 2 now"
    So, when I add it to the combo (which is actually a html:select), I wanna show the description and get the value.
    Which of them should I use?

    public Map getAtributosColecao(){
    Map mapa = null;
    mapa.put("colecao","Cole��o");
    mapa.put("descricao","Descri��o");
    return mapa;
    }is it correct? 'cause when I call it from another
    class, I get a nullPointerException...Of course you get that exception.
    Map mapa = null;Ok, mapa is null here.
    mapa.put("colecao","Cole��o");Duh?

  • MRP list: collective requirements (MD06) in the background mode

    Hi Friends,
    We have requirement to run MRP list: collective requirements (MD06) in the background mode per MRP controller. Is there any way we can run MD06 in the background?
    Appreciate your response.
    Thanks,
    Srinivas

    Dear Srinivas
    if you need to run planning as a background job please try t-code MDBT;
    as far as i know you can't run MD06 as a backgroun job.
    you could ask your abaper to create a custom program based on functional module MD_MRP_LIST_OVERVIEW
    after that you will set up this custom code as a background job.
    good luck!

  • How to call BULK COLLECT using JDBC in JSP?

    Hi
    I am using BULK COLLECT instead of CURSOR in my Stored Procedure.
    How to use these stuff in JDBC.
    If i am using CURSOR means
    cs.registerOutParameter(1,oracle.jdbc.driver.OracleTypes.CURSOR);
    is used.
    Which types i have to use?
    I am retriving morethan one record using FOR. LOOP in SP and before that
    BULK COLLECT is used in SELECT query..
    Can you give jsp code for this?
    Thanks

    you may find related sample jdbc code on otn - http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
    Best regards.

  • Add_item : Attributes list collection sort order

    Hello:
    I created multiple custom attributes and added them to my custom item type. I need to apply these attributes while adding an item programmatically.
    1) How do i define the order of the Attributes list via the Portal builder so as to match the corresponding values read from a list/table,etc. ?
    2) The ordering arrow buttons in the attribute list of my custom item type does not match the result set from my query. I tried all options of "order by" clause. Here is the query - (componenttype is the name of my custom item type)
    select iatts.ID
    ,atts.caid
         ,atts.DATA_TYPE     
         ,atts.CAID
         ,atts.NAME,atts.DISPLAY_NAME
         ,iatts.ITEM_TYPE_ID
    from wwsbr_item_types itypes
    ,wwsbr_item_type_attributes iatts
    ,wwsbr_attributes atts
    where --itypes.caid = 133
    itypes.name like 'ComponentType'
    and itypes.ID = iatts.ITEM_TYPE_ID
    and iatts.ATTRIBUTE_ID = atts.ID
    --and atts.CAID = 133
    order by atts.id
    3) I need to expect a certain order of the attribute ids, when bulk collecting into the attributes array, in order to populate the values collection in the same. So, how do I determine the order of the attributes ids ?
    4) Is there a better way to do this ?
    Thank You.
    regards
    Ananth

    Document Sets are great tools for grouping multiple documents together. However, if every set has exactly one document, it would be better to just upload the file and not place it within a Document Set:
    Uploading documents using object model - http://msdn.microsoft.com/en-us/library/office/ms454491(v=office.14).aspx
    Uploading documents using web services -
    http://cecildt.blogspot.com/2010/10/upload-documents-to-sharepoint-2010.html
    If you have requirements to use Document Sets, keep in mind that this adds a layer of complexity beyond a simple Document Library. Behind the scenes, each Document Set is treated as a separate folder, and although can you query items within it, there might
    be extra steps for getting the sort order to ignore the folder structure. Can you try setting the Scope to be "Recursive" and also specify that you are looking only for files and not folders:
    <Eq><FieldRef Name='FSObjType'/><Value Type='Lookup'>1</Value></Eq></Where>
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Inserting oracle objects / collection using JDBC

    Hi people,
    I want to insert objects with collections(nested tables) into oracle database using my java JDBC. I believe there are two ways, one using strong types and the other as weak. I am using the weak types.
    This is what I have got so far:
    create or replace type town_ty as object(
    name varchar2(20)
    create or replace type country as object (
    name varchar2(20),
    towns town_ty
    create table country_tab of country_ty;
    Can any one kindly give or show me an example how to insert data into the above table using weak typed JDBC?
    Thanks very much

    Hi
    You should find what you are looking for in the samples provided here http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.html.
    HTH
    Chris

  • Query/Report to list collections in a Folder

    does anyone have a query / report that lists the collections contained in a folder? I've found powershell scripts for this but they're not translating over with the same logic as a query.
    Thanks.
    Jason

    does anyone have a query / report that lists the collections contained in a folder? I've found powershell scripts for this but they're not translating over with the same logic as a query.
    The logic should be fairly close. What does the PowerShell script look like?
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

  • Passing list collection from page to page

    Using wp 8.1 and c#, I need to build a collection on one page1, then use the collection throughout the app for every page including page2, page3, page4, etc.
    Can anybody offer advise to consider?
    I thank the Lord Jesus for your kind effort and patience with me (Jeremiah 9:23-24 of the Holy Bible).

    Is this Silverlight or is it windows store app?
    It doesn't matter a great deal.
    You have three options.
    1)
    You can add any old object you like to resources and there's an application scoped set of resource.
    In windows store apps I think that'd be app.current.resources and in silverlight it's application.current.resources.
    You do:
    Application.Current.Resources.Add("somekey", yourlist);
    and that adds it to your resources.
    App.current... for win store app.
    To get a reference back to that thing ( note, it's a reference and therefore the same object).
    List<t> mylist =Application.Current.Resources["somekey"] as List<t>;
    Obviously, that list can instead be some other sort of collection and <t> is the type of the objects in it.
    You can see this approach used in one of my WPF samples:
    https://gallery.technet.microsoft.com/Dynamic-XAML-Composed-View-e087f3c1
    This shares two observable collections in a similar manner.
    It proves they are definitely the same object because you can edit a person and see the changes immediately in the corresponding datagrid row.
    2)
    You could alternatively send the List<t> using Mvvm Light messenger in an object and subscribe to that object type in the "receiving" pages.  They would have to be in memory and I think option 1 is your best bet.
    3)
    You could create the collection in one place - like mainpage eg.  Then pass that collection via the constructors of the other pages as you new them up.  I don't really like this approach because it introduces a dependency to all those pages which
    means testing etc is harder.   I don't consider it a professional approach if there's an alternative - but it's an approach plenty of professionals advocate so your mileage may vary.
    It's not really any simpler than using resources.
    Hope that helps.
    Recent Technet articles:
    Property List Editing ;  
    Dynamic XAML

  • Source list Collective processing

    Hi All,
         I have a scenario where i need to do Collective generation of Source list for few vendors using tcode ME05..
        As i have not used this functionality earlier, can you tell me in detail how to execute this in system ...
          Thanks
        Regards..
        Akkshaya

    Hi
    you generate the source list for several materials by using ME05.
    1.Enter the materials for which source list to be generated
    2.Enter the plant
    3.Select all records for Material and Plant (System should consider only outline agreement items, only info records, or both be taken into account)
    4. Enter validity periods
    5. Select  Exixting records option based on requirement
    Execute 
    A list of the source records to be generated is displayed. Already-existing source list records whose validity periods are thus changed are also listed.
    Select the source list records you want to include in the source list.
    <b>Fixed or blocked Source list records:</b> You can mark a source list record as "fixed" or block it. A "fixed" source represents the preferred source of supply, whereas a "blocked" source is one from which you are not allowed to order.
    Select the desired source list record. Then choose Edit -> Fix, or Edit -> Block.
    Choose  save to store the selected source list records for the displayed material in the source list.
    Exception messages are displayed by the system. Press ENTER to continue the saving process.
    Regards
    Ramakrishna

  • List collections

    Hi,
    I have 2 lists in java like these 2.
    First has some distinct values as
    #home
    #wall
    #Bed
    The second list has values as
    #home
    vlu
    3 rooms
    etc
    #wall
    som value
    value
    #home
    some value
    and so on
    I want that when I iterate to first list to find all corresponding values
    the output should be something similar with
    #home
    vlu
    3 rooms
    etc
    some value.
    Can you help me with this problem?
    Thank you,
    Cosmin

    Just iterate them both at the same time.

  • Program to list JDBC drivers

    Hi everyone,
    I use the following code to list JDBC drivers on my system.
    private static void listDrivers() {
    //Get all the JDBC drivers
    Enumeration<Driver> driverList = DriverManager.getDrivers();
    //print out all the drivers using a loop
    while (driverList.hasMoreElements()) {
    Driver jdbcDriver = (Driver)driverList.nextElement();
    System.out.println("JDBC Driver: " + jdbcDriver);
    It lists JDBC-ODBC bridge:
    JDBC Driver: sun.jdbc.odbc.JdbcOdbcDriver@19efb05
    After I installed Microsoft SQL Server JDBC driver. I ran the above program again. Expecting it would return this new driver as well. But, the output is still the same.
    Why??? What did I do wrong? How do I get the program to list all the JDBC drivers on my system?
    Thanks in advance for your help!
    Eric

    jwenting wrote:
    Where you went wrong was in assuming that just having a jar somewhere on your computer will automatically put it on the classpath of your little application.
    Or maybe you went wrong in assuming that jdbc magically detects any jar anywhere on your computer that has a driver in it without being told where to look for that jar.Well, there's that. But, there is also the fact,OP, that the API docs says that the method getDrivers returns all currently loaded Drivers. In other words, OP, even if the jar is on your Classpath, getDrivers won't list it until you've done Class.forName("DriverClass") or DriverManager.registerDriver("DriverClass").
    IOW, OP, read the API docs.
    Edit: And, no, there is no Class/method (AFAIK) that will search your classpath for any/all possible Driver classes.

  • HELP: collection as in parameter of SP using jdbc

    Hi, everyone:
    i'm trying to pass an array of int value to a stored_procedure using jdbc, but i cannot figure out how to write the exact code.
    i always get the same exception: java.sql.SQLException: invalid name schema.
    i have searched this section and found some examle(Call a procedure/function with an array as argument i tried that example code, but it cannot work too, the same exception.
    here is my jdbc code:
    String driver = "oracle.jdbc.driver.OracleDriver";
    String strUrl = "jdbc:oracle:thin:@127.0.0.1:1521:test";
    Connection conn = null;
    Class.forName(driver);
    conn = DriverManager.getConnection(strUrl, "zzuliTV", "123456");
    CallableStatement proc = null;
    proc = conn.prepareCall("{ call TEST_TABLE_INT_PARAM(?,?) }");
    int elements[] = { 1, 2, 3, 4 };
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TEST_PACKAGE.ID_TABLE", conn);
    //ARRAY aArray = new ARRAY(desc, conn, elements);
    //proc.setInt(1,-1);
    //proc.setArray(2, aArray);
    //proc.execute();
    proc.close();
    conn.close();
    pl/sql code:
    create or replace
    PACKAGE TEST_PACKAGE AS
    type ID_TABLE is table of number(10,0);
    END TEST_PACKAGE;
    in the jdbc code, the statement "ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TEST_PACKAGE.ID_TABLE", conn);" caused the exception.
    i have tried the code "ArrayDescriptor.createDescriptor("ID_TABLE", conn);" or written the pl/sql nested table globally or written an varray instead, but all failed, always the same exception.
    i use oracle 11g.
    Could anyone help me, thanks a lot.

    The error might be caused by your collection being defined inside of "TEST_PACKAGE", which I presume is a PL/SQL package.
    JDBC does not support Object nor Collection types defined inside packages.
    So, your attempt to globally define your "ID_TABLE" is the correct way to go.
    create type id_table as table of integer;
    or
    create type id_table as varray(#) of integer;
    Both are valid global definitions. I think that you said that you tried this unsuccessfully.
    You may want to try rewriting your elements declaration as follows.
    int elements\[] = new int\[]{1, 2, 3, 4};
    However, your declaration is probably fine. Another suggestion is to use CallableState.setObject() instead of setInt() and setArray().
    proc.setObject(1, new Integer(-1));
    proc.setObject(2, aArray);
    Also note that for 11g, the driver class is "oracle.jdbc.OracleDriver"
    Only other thing I can think of is to make sure the collection is defined in your schema or, if another, you have permission to it.
    That's all I can think of. Here is a link that describes using collections with JDBC. You may find it useful.
    http://st-doc.us.oracle.com/11/111/java.111/b31224/oraarr.htm#g1072333

Maybe you are looking for

  • HP Pavilion dv4-2170us - more heat and lound sound

    Not sure whats happening with my laptop HP Pavilion dv4-2170us windows 7 home premium... More heating and loud sound / noise.

  • Auto open Itunes when plug in Iphone

    My mac used to open Itune when i pluged in my ipone but now it opens iphoto and not itunes. I can open itunes manualy and the phone is there and works fine but i would like it to open it when i plug in not iphoto. Any ideas. (4s iphone)

  • Mountain Lion and Lion very slow on Macbook 13' 2010 Middle

    The problem is the Mountain Lion and Lion very very slow, but Snow Leopard was fast. The Lion bit faster, the Mountain Lion is much slower. Animations are choppy and slow, but sometimes fast, but mostly random stuttering. If i have multiple windows o

  • How to use audio and mic with multipoint server with out it crashing on you

    how to use audio and mic with multipoint server with out it crashing on you when i use them to make calls thru my station (zero client) at the same time it crashes on me and i need to restart the multipoint is there a setting i may have mist that ena

  • US HR Payslip

    Hi there, What is the programs and forms name for US HR Payslip? tq