How to construct a ResultSet from a Collection?

I've found lots of articles/postings describing how to create a Collection given a ResultSet, but I need the
opposite.
Anybody know of code that will create an object with the ResultSet interface that can be constructed (or populated after fact) with a Collection?
Sun's CachedRowSet can't do this unless I'm missing something. Ideally it would have a constructor that took a Collection as a parameter.

import java.sql.*;
import javax.sql.*;
import sun.jdbc.rowset.*;
public class RowSetExample
public static void main(String args[])
try {                     
// create a new rowset and populate it...
sun.jdbc.rowset.CachedRowSet crs = new sun.jdbc.rowset.CachedRowSet();
sun.jdbc.rowset.RowSetMetaDataImpl rsmdi = new sun.jdbc.rowset.RowSetMetaDataImpl();
int colCount = 2;
rsmdi.setColumnCount(colCount);
rsmdi.setColumnDisplaySize(1, 5);
rsmdi.setColumnName(1, "ID");
rsmdi.setColumnType(1, java.sql.Types.INTEGER);
rsmdi.setColumnTypeName(1, "INTEGER");
rsmdi.setTableName(1, "MY_TABLE");
rsmdi.setAutoIncrement(1, false);
rsmdi.setSearchable(1, true);
rsmdi.setColumnDisplaySize(2, 20);
rsmdi.setColumnName(2, "NAME");
rsmdi.setColumnType(2, java.sql.Types.VARCHAR);
rsmdi.setColumnTypeName(1, "VARCHAR");
rsmdi.setTableName(2, "MY_TABLE");
rsmdi.setAutoIncrement(2, false);
rsmdi.setSearchable(2, true);
crs.setMetaData(rsmdi);
java.util.Map map = new java.util.HashMap();
map.put(new Integer(1), "AAA");
map.put(new Integer(2), "BBB");
map.put(new Integer(3), "CCC");
java.util.Iterator iter = map.entrySet().iterator();
while (iter.hasNext()){
java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();
int idx = 0;
crs.moveToInsertRow();
crs.updateObject(1, entry.getKey());
crs.updateObject(2, entry.getValue());
crs.insertRow();
crs.moveToCurrentRow();
crs.beforeFirst();
while (crs.next()){
System.out.print(crs.getObject(1));
System.out.println(": " + crs.getObject(2));
}catch (SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());

Similar Messages

  • How do I move photos from a collection to a flash drive?

    How do I move photos from a collection to a flash drive?  I want them in the same order and edited the same as they are in the collection.

    Drag and drop?  Copy folder?

  • How to add a photo from a collection to a book in Lightroom 4.1?

    How to add a photo from a collection to a book in Lightroom 4.1?

    Save the book, then go back to Library and add the photos there.

  • How to get a resultset from Stored Procedures

    How to efficiently and portably get resultsets from Oracle stored procedures? Oracle does not seem to follow JDBC standards here. A standard way in Oracle is to use a ref cursor and call getObject() on CallableStatement. However, Oracle seems to get all the data in the resultset in getObject(), which is inefficient and leads to large memory usage when the resultset is large.
    Another way in Oracle is to use getCursor() on an OracleCallableStatement, which is efficient but not portable across different application servers. For example, in WebSphere, this OracleCallableStatement is not available if we want WebSphere to manager the datasource.
    Any ideas will be greatly appreciated. Please email to [email protected]

    Oracle JDBC did not support return a result set, if you are using Oracle 9i, you can use pipeline function, then using the TABLE() function the get the row.
    Good Luck.
    Welcome to http://www.anysql.net/en/

  • How do I add photos from another collection to my saved Book?

    Hi,
    In my lightroom library I have created a collection set called "Wedding". As I have 1000 photos from my wedding, within this Collection Set I have created 10 or more Collections to organise these photos (Ceremony, Reception, First Dance, etc.).
    I have created a new 'Book' which as expected, has created a new Collection within my 'Wedding' collection set.
    When I first create the book (before saving it) it seems like I can click on a page, then browse my Collections and add the photo that I desire to the page.
    After I have saved the book, I can't so this. I want to work on my book later, and use my existing organisation of photos, and add photos to my books from these collections.
    I know I am missing something basic (I am new to lightroom). I don't understand why I can't add a photo to my book after I have saved it.
    Each time I click on one of my other collections, a new unsaved book appears in the main project window.
    I have worked out that if I copy all my wedding photos into the new "Book" collection, then my photos are available for use - but this defeats the purpose of organising my photos into separate collections, and it doesn't seem like you can create a sub-collection within the Book project.
    I also can't seem to find any documentation to explain this properly.
    Any help would be apreciated - or if I coud be pointed to a good resource.
    Cheers,
    Mandy.

    Thanks for the response.
    I saw these discussions previously, but not of them seem to answer my question (nor confirm that what I am trying to do cannot be done).
    If I want to create a "Wedding Album" book, do I have to firstly use the Library module to drag ALL the photos I may want to use into my "Wedding Album" collection (saved book) ?
    This seems annoying as I have already categorisied my 1000+ wedding photos into separate Collections using the Library (so that I can find the one I want easier).
    It seems as though the Book module would function much better if you could create a book, choose a page that you want to add a photo to, then browse through your pre-configured collection sets & collections, and add photos to the book from the navigation panel on the left when you have the "Book" module open. (Rather than having to copy the photo first into the "Book" 's Collection, then adding it to the page that you want)
    Mandy.

  • How do I move photos from one collection to another in Photo app ios7?

    When upgraded my iPad to IOS 7, it automatically sorted photos into collections that are not correct and I would like to sort them into correct events.

    If you create your new album and give it a name you can then select where you wish to add new photos from.  For example either select Photos or Albums from the bottom of the screen and select the photos you wish to add to the new Album.
    Regards,
    Steve

  • How can I extract data from embedded collection??????

    I have 4 classes (class1, class2, class3, class4). Each of them contains properties, methods and a set (HashSet). The set declaration code is: private Set set1;
    The initialization occurs in the appropriate method (however I did declare and initialize as private Set set1= new HashSet(); without success). Each Set is declared and initialize in their own class. The insert and update method works perfectly well.
    When I load class1 object, I can see at runtime in the debug feature all properties data as well as all set elements (set1, set2, set3, and set4). I can extract the data from all properties belongs to the class1 as well as the set1 element. However I cannot extract the data from the set2, set 3 and set4. By writing the following �String s = class1.set1(). Property name;� and I will get the information. The problem that I have is that I cannot write the following �String s= class1.set1().set2().property name;� since set2 cannot be seen. What should I do to get the info from the other set collection???? The loading method provide an object that contains everything. This object is equal as class1 and the set are embedded one inside the other.
    Used hibernate and Struts.
    Could someone help???? Many thanks

    Are we talking about Java source code here or some weird expression language?
    Can you post a minimal, example Java program that demonstrates your problem?

  • How to get the resultset from the field number(11,2) ???

    i can get it by rs.getString() but i do not know how to convert String to Number(11,2)?

    i dun know exactly what u meant, but to convert string to int is to use Integer.parseInt("555")...

  • HT4059 how do you delete books from your ibooks collection

    How can you delete ibooks from your collection list.  I no longer want them on my mini ipad

    Open the iBooks app. Tap the Edit button at the upper-right. Tap the books you wish to delete. Tap the red "Delete" button. Or you can uncheck them on the Books tab in iTunes on your computer and they'll be removed when you sync.
    Regards.

  • Getting resultset from out parameter ref cursor

    hi,
    i have written one procedure which return one refcursor as out parameter.
    when i am calling that proceduer how can i retrive that resultsets in my current program.
    ex
    DECLARE
    type A is ref cursor;
    B A;
    x NUMBER :=0;
    BEGIN
    APPSEARCH(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,B);
    FOR i in b
    loop
    x:= x+1;
    end loop;
    DBMS_OUTPUT.PUT_LINE('ANS '||x);
    END;
    but it is giving error
    please advice
    thanks
    siva

    Thanks alessandro,
    SQL> DECLARE
    2 type A is ref cursor;
    B A;
    3 4 C b%rowtype;
    5 d NUMBER;
    6 BEGIN
    7 APPSEARCH(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,B);
    8 loop
    9 fetch b into c;
    10 exit when b%notfound;
    11 DBMS_OUTPUT.PUT_LINE('ANS '||c%rowcount);
    12 end loop;
    13 close b;
    14 END;
    15 /
    C b%rowtype;
    ERROR at line 4:
    ORA-06550: line 4, column 4:
    PLS-00320: the declaration of the type of this expression is incomplete or
    malformed
    ORA-06550: line 4, column 4:
    PL/SQL: Item ignored
    ORA-06550: line 9, column 17:
    PLS-00320: the declaration of the type of this expression is incomplete or
    malformed
    ORA-06550: line 9, column 4:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 11, column 35:
    PLS-00320: the declaration of the type of this expression is incomplete or
    malformed
    ORA-06550: line 11, column 6:
    PL/SQL: Statement ignored
    i dont know how to transfer the resultset from the procedure refcursor out parameter to my local cursor variable please help

  • Getting resultset from some other java program

    how could i getting resultset from some other java program?
    plz

    a resultset is directly linked to your (prepared) query.
    for performance(and synchronization) reasons, you do want to retrieve the data as fast as possible and then release it.

  • Return Resultset from Procedure

    Hi --
    This may seem like a very elementary question, but can anyone tell me how to return a resultset from a function or procedure?
    Thanks,
    Christine

    if i understand your question correctly. a function return value is mandatory. while procedure is optional you had to use the out at the parameters. examples:
    CREATE OR REPLACE FUNCTION get_age (pBday Date) RETURN number IS
      vAge          Number := 0;
    BEGIN
      vAge := (Months_Between(sysdate,pBday) / 12);
      Return (vAge);
    END;
    CREATE OR REPLACE PROCEDURE get_age_procedure (pBday In Date, pAge Out Number) IS
    BEGIN
      pAge := (Months_Between(sysdate,pBday) / 12);
    END;
    /you need to create a reference cursor type object to achieve a result sets.
    CREATE OR REPLACE package TYPES AS
        TYPE cursorType IS REF CURSOR;
    END;

  • How to construct table in jsp for the resultset from helper class

    Hi Dudes!!!
    Want to construct table in jsp for the resultset, but the resultset are retrieved at the helper class.I constructed Table in Helper class Using StringBuffer and return it as string from the helper class.Is their any other feasible and efficient way to construct table in Jsp for the resultset from Helper class.Solution will be highly appreciated.Thanx in Advance.

    no, we can't.
    Certainly noone can with such vague specifications even if they had the intent to do so.
    "the computer", which computer?
    "attach to our current page", what is meant by that?
    And noone should ever help you if you're planning to breach security anywhere.

  • HT1473 Could you remind me how to synch music backl from my ipod to my compputer - my ipod has my whole collection but my laptop has been upgraded and i lost my library

    Could you remind me how to synch music back from my ipod to my computer - my ipod has my whole collection but my laptop has been upgraded and i lost my library

    Follow the steps given here...
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive

  • Recently, when I create a new album (untitled), it immediately fills with picture either from the album above it or, if I have a Faces collection open, with the pictures from that collection. Why and how do I fix it?

    Recently, when I create a new album (untitled), it immediately fills it immediately fills with picture either from the album above it or, if I have a Faces collection open, with the pictures from that collection. Why and how do I fix it?

    When a new album is created it will fill with whatever is in the right hand window,  If you're in the Events or Photos mode it will contain all photos in the library.  Yes, strange behavior.
    OT

Maybe you are looking for

  • How to delete the committed row from a table from its VOImpl class ??

    I am new to ADF and I have problem to solve. To perform roll back I am using fetching key before roll back and setting it after undo operation, so that I can stay back in the currently selected row. But in my case I am using application model commit

  • Can't connect to Exchange2003 Server through WRT54GS (via wireless)

    I'm having problems conencting to my MS Exchange 2003 server, from an Outlook 2003 Client, when using wireless on a WRT54GS. Hard wired - works fine. Wireless - connection times out ("unable to connect to exchange server") I can browse the internet t

  • Iphoto not working properly after installing snow leopard...

    the two main problems are... 1) when editing in full frame, if I zoom in on the photo and try to move around with a two finger scroll, there is a big delay between me moving to where I want to be and the photo actually getting there. 2) when editing

  • HREAP not working correctly

    I have a 4404 with 1242's running 6.0.199.0 all ap's are in HREAP mode(at remote sites). When the controller goes down all users are disconnected. The SSID in question is using WPA-PSK & has HREAP local switching enabled. the clients get local IP Add

  • SELECT CASE IN PL/SQL

    I NEED TO KNOW HOW TO RUN IN PL THE STATEMENT select case when ... thanks