Storing sql recordset in an array, or list, or similar

I should probably understand hashmaps better before posting this, but if someone could point me in the right direction, I'd appreciated it.
I'd like to store a sql resultset having an integer and a string in an array, or list, or similar. That is, I'd like to close the recordset and still have the data stored somehow.
Problem wth an array is, as I understand it, even a multi-dimensional array has to be of the same type:
String [][] records ...or
int [][] records;
I'd like to declare:
int[]String[] records;
...and store the resultset into this array(list, or collection, or whatever) in a while loop.
ResultSet rs = statement.executeQuery();
int i = 0;
while ( rs.next() ) {
records[0] = rs.getString( "ObjectId") ;
records[i][1] = rs.getString( "ObjectName" );
rs.close();
statement.close();
Any ideas appreciated.
Amboss

You could declare create a your own class as -
class MyRecord extends Object {
int id;
String name;
public MyRecord(int id, String name) {
this.id = id;
this.name = name;
}Then use a Vector to save the records as you iterate
over the ResultSet
Vector records = new Vector();
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
records.add(
new
MyRecord(rs.getInt("ObjectId"),rs.getString("ObjectNam
e"));
}To retrieve records you must use the get() method of
Vector.
MyRecord rec = (MyRecord)records.get(i);
Aren't you going to put parameter to Vector<?> ?
this is based on the JDK Generics 1.5

Similar Messages

  • How to create a stored procedure that accepts an array of args from Java?

    I am to be creating a stored procedure that accepts an array of arguments from Java. How to create this? thanks
    Sam

    Not a PL/SQL question really, but a Java one. The client call is done via ThinJDBC/OCI to PL/SQL, This call must be valid and match the parameters and data types of the PL/SQL procedure.
    E.g. Let's say I define the following array (collection) structure in Oracle:
    SQL> create or replace type TStrings as table of varchar2(4000);
    Then I use this as dynamic array input for a PL/SQL proc:
    create or replace procedure foo( string_array IN TStrings )...
    The client making the call to PL/SQL needs to ensure that it passes a proper TStrings array structure.. The Oracle Call Interface (OCI) supports this on the client side - allowing the client to construct an OCI variable that can be passed as a TStrings data type to SQL. Unsure just what JDBC supports in this regard.
    An alternative method, and a bit of a dirty hack, is to construct the array dynamically - but as this does not use bind variables, it is not a great idea.
    E.g. the client does the call as follows: begin
      foo( TStrings( 'Tom', 'Dick', 'Harry' ) );
    end;Where the TStrings constructor is created by the client by stringing together variables to create a dynamic SQL statement. A bind var call would look like this instead (and scale much better on the Oracle server side):begin
      foo( :MYSTRINGS );
    end;I'm pretty sure these concepts are covered in the Oracle Java Developer manuals...

  • Accessing arrays within lists

    Hi,
    I have a linked list with arrays of type byte stored in. I have managed to access each individual array using list.get(i) but how can I access an individual element of a specific array in the list?
    Thanks and regards,
    Krt_Malta

    void f(List<byte[]> list) {
        byte me = list.get(0)[17];
    }

  • How to create an XML/RSS feed from a SQL recordset?

    I've been trying to find either a tutorial or extension that will allow me to take a SQL recordset, and create my RSS feed on the fly.  Not having much luck... anyone out there have a suggestion??

    Thanks PC!
    I made it work using:
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    factory.setIgnoringComments(true); // We want to ignore comments
    // Now use the factory to create a DOM parser
    DocumentBuilder parser = factory.newDocumentBuilder();
    //TransformThisStringBuffer is a string buffer wich contain the 'XML document (String)'
    InputStream in = new ByteArrayInputStream(TransformThisStringBuffer.toString().getBytes());
    // Parse the InputStream and build the document
    Document document = parser.parse(in);
    But which one is faster InputSource or InputStream, were would you put the "new InputSource(new StringReader(yourString))" in the above code?

  • SQL function column in drop down list's data provider's query

    Just wondering, if it is somehow possible to use SQL function column for drop down list through data provider.
    At the moment, I am using id column as return value and name as display value from this query through CachedRowSetDataProvider:
    SELECT ALL someTable.Id,
    someTable.Name,
    someTable.Postal_Code,
    FROM someTable
    However, I want to change display to use calculated column as display value, for example Name_PostalCode from below mentioned changed query:
    SELECT ALL someTable.Id,
    CONCAT(someTable.Name, ' - Pin Code: ',someTable.Postal_Code) Name_PostalCode ,
    someTable.Name,
    someTable.Postal_Code,
    FROM someTable
    But JSC doesn't seem to like this.
    Is it someway possible to achieve this?
    Thanks.

    >
    But JSC doesn't seem to like this. Can you explain more. When doesn't it like it, in the design view, in the query editor, when your run it? What is the error you are seeing?
    See http://blogs.sun.com/divas/entry/displaying_multiple_fields_in_a

  • PL/SQL function returning a colon delimited list of headings

    Hello,
    Apex version 4.1.0.23. I am editing an existing classic report which has the column heading option set to 'PL/SQL function returning a colon delimited list of headings'. I have been looking for some time but I cannot find where this PL/SQL function is defined. Can any one point me to the right direction? I do not see anything in the documentation either.
    Thanks,
    Usman

    Hi Usman,
    I looked into this issue and found that there's some JavaScript code executed when opening the page with the PL/SQL headings option enabled, or when selecting that option after loading the page, and this JavaScript attempts to set a background color for the column heading fields. Since we only display attributes for up to 100 columns, this JavaScript fails once you have more than 100 columns.
    I would certainly agree with Tony that 60 or 100 columns are a bit much. But there should be some indication why something is not working, even if it's only a message stating that there's only a certain number of columns supported. So I'll log a bug to improve this in APEX 5.0.
    Thanks,
    Marc

  • Using Arrays.asList: Is Array[x] == List.get(x)

    I have an Object[] Array and I wish to remove index 'x' from that Object[] Array. If I use Arrays.asList() passing in the existing Object[] Array I will get new List Object containing the objects from the Object[] Array. Is it guaranteed that index 'x' from the Object[] Array is the same Object from the index 'x' in the new List?
    Object[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_3"};
    List list = Arrays.asList(obj);
    assertTrue(obj[0] == list.get(0));
    assertTrue(obj[1] == list.get(1));
    assertTrue(obj[2] == list.get(2));
    assertTrue(obj[3] == list.get(3));Are the above assertions always guaranteed to be true?

    Jared_java_dev wrote:
    I thought the JavaDoc API would state it as well. I did originally check that.
    I agree that it should keep the order but I wanted to verify this behavior. It would make some coding logic much more simple.
    Objective is to remove ojb[2]
    String[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_
    //Perferred logic
    List<String> list = Arrays.asList(obj);
    //remove unwanted element
    list.remove(2);
    //create new Object[] without unwanted element
    obj = (String[]) list.toArray();
    {code}
    as opposed to
    {code}
    String[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_
    //unwanted logic
    List<String> list = Arrays.asList(obj);
    for (int x = 0; x < obj.length; x++) {
    // == or String.equals
    if (list.get(x) == (obj[x])) {
            list.remove(x);
    obj = (String[]) list.toArray();I guess that I could write a sample program and run to verify this .
    Thanks for everyone's input.No, you won't be able to simply 'delete' items from this array-backed list. It is a fixed size list, so additions/deletions are expected to throw exceptions.
    So now my question is: Why is the master an array in the first place? Seems like it should be a List from the get-go.

  • Using an 9 by 9 Array of Lists

    I am currently programming a suduko puzzle and am using a 9 by 9 array of lists to do this.
    List[][] A;                          
    A = new List[9][9];this creates a 9 by 9 array of lists but when i use:
    List A[x][y] = new List[A.add(ob1)][A.add(ob1)];I get an error. Does anyone now how to correctly add numbers to the lists that i have just created.
    Help is much appreciated

    I get an error. Only one? Oh well, I guess you scared the poor compiler to death with that piece of code. If you have any pity at all for your compiler, read the array tutorial:
    http://java.sun.com/docs/books/tutorial/java/data/arraybasics.html
    and then the list tutorial:
    http://java.sun.com/docs/books/tutorial/collections/interfaces/list.html
    If you really need an array of lists, that is...

  • How to restore this kinda XML into an array or list?

    I have a XML file like this
    [msgboard]
    [message]
    [subject] subject [/subject]
    [body] text body [/body]
    [followups]
        [message]
            [subject] subject [/subject]
            [body] text body [/body]
            [followups]
                       [message] ...
            [/followups]
        [/message]
    [followups]
    [/message]
    [/msgboard]so the XML can be unlimited deap.
    I want to read it into an array or list or something like that, so I can use the data.. but how should I store them? any ideas ? thanks

    Please refrain from cross posting http://forum.java.sun.com/thread.jspa?threadID=785000

  • Converting Arrays to List

    Hi,
    I have the following function that converts String[] to List of int and it's working
    private String putSelect(){
            String msg = SUCCESS;
            try{
                if (session.get("selectCat") != null){               
                    String[] aux = (String[])session.get("selectCat");
                    List aux2 = new ArrayList();
                    for (int i=0;i<aux.length;i++){
                      aux2.add(Integer.parseInt(""+aux));
    setSelectCat(aux2);
    }catch (Exception e) {       
    msg = ERROR;
    System.out.println(e.getMessage());
    return msg;
    but I know that is possible to convert from array to list using :
    Array.asList
    but I need that the resulting list be of int not String, is there a way to modify this setSelectCat(Arrays.asList((String[])session.get("selectCat"))); in order for that to be possible?
    thanks, V

    if you're using java 1.5, then a better loop might be:
    for (String num : aux) {
       aux2.add(Integer.parseInt(num));
    }The variable aux is already a String, so doing "" + aux is pointless. I don't know if a compiler would clean that up for you or not. I'm told that a 'for / in' loop as coded above is marginally faster than an incrementor loop.
    Enjoy!

  • How Do I Call PL/SQL Stored Procedure That Returns String Array??

    I Have Problem Calling An Oracle(8i) Stored Procedure That Returns Array Type (Multi Rows)
    (As Good As String Array Type..)
    In This Fourm, I Can't Find Out Example Source.
    (Question is Exist.. But No Answer..)
    I Want An Example,, Because I'm A Beginner...
    (I Wonder...)
    If It Is Impossible, Please Told Me.. "Impossible"
    Then, I'll Give Up to Resolve This Way.....
    Please Help Me !!!
    Thanks in advance,

    // Try the following, I appologize that I have not compiled and run this ... but it is headed in the right direction
    import java.sql.*;
    class RunStoredProc
    public static void main(String args[])
    throws SQLException
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    catch(Exception ex)
    ex.printStackTrace();
    java.util.Properties props = new java.util.Properties();
    props.put("user", "********"); // you need to replace stars with db userid
    props.put("password", "********"); // you need to replace stars with userid db password
              // below replace machine.domain.com and DBNAME, and port address if different than 1521
    Connection conn =
    DriverManager.getConnection("jdbc:oracle:thin:@machine.domain.com:1521:DBNAME", props);
    // replace "Your Stored Procedure" with your stored procedure
    CallableStatement stmt = conn.prepareCall("Your Stored Procedure");
    ResultSet rset = stmt.execute();
    while(rset.next())
    System.out.println(rset.getString(1));

  • PL/SQL comparing with an array

    Hi,
    I have PL/SQL script which contains an IF statement as follows:
    IF(a.col1 in (select b.col1 from tablex b where b.col2=0))
    However, I get an error message telling me a subquery is not appropriate there.
    So, I'm trying to do the same comparison some other way. I understand there is no such thing as arrays in PL/SQL but that table type variables do the same kind of thing. Is there a way perform the above IF statement using this method (or perhaps there is a better one?)
    Any suggestions most appreciated!
    Diarmuid

    Hi,
    I think I expressed myself badly, what I want to know is whether the following is possible for a comparison in pl/sql
    where col1 in (tablex)
    where I have populated tablex with a list of different values?
    at the moment, I have put in these values manually
    where col1 in (12, 34, 56, 78)
    Those four values are the result of a long complicated query and I want to replace them in the brackets by something not hard-coded, but I don't know how to do it.

  • Arrays to lists in db or something better?

    I have a form that is dynamic in that it first asks the user
    how many entries they will be making. If the user says 5, an array
    is created to accomodate that such as
    <cfset SESSION.newarray = structNew(2)>
    The form is generated using a cfloop to create the rows in
    accordance with the number of entries requested.
    I don't want to put these values into a list and into the
    database, but the user can request up to 20 rows. In this case the
    user is asked how many new customers he wishes to add to the
    database, then the next page creates the array, loops through the
    <cfinput> lines and creates the table. THe results of the
    form is then stored into session variables, so that the user can go
    back and forth through the forms without losing data, and not
    requiring a database read/write each time, until the end. THen the
    data from the array is fed into the database for storage.
    My question (finally!) is this: Is it more effecient to
    create 20 columns in the database to store each of the possible
    entries, or create a list and store the data in lists, pulling the
    lists out and finding data from the lists or is there a better way?
    Thanks.

    A better way would be to store 20 records. Sounds like a
    course in data modelling would benefit you.

  • Can't see my Oracle stored procedure in the avalable data source list

    Post Author: Moori
    CA Forum: Data Connectivity and SQL
    Hello All,
    I've created an Oracle stored procedure which I need to use it's returned data in my crystal report but I can't find it in the data source list.
    I'm using the same schema & database and user as my sp was created on.
    Please advise.
    Moori

    Jim (also Geoff and Hal)-
    Still haven't solved this. Here's another try at a screenshot, showing just below this text for me, of my Library interface showing the C drive listed in the left panel and not showing the C drive contents. Only, as you said is intended, what is already in Lightroom.
    I thought if I was not in "Catalog" I had been able, in the past, to select from anything in my C crive simply by opening that folder in the panel.
    When I click import it is usually - from memory - to start the import of the already selected items. For a time that's what was happening from the above screen if I selected Import. It would apparently start re-importing the selected items and without presenting the usual familiar dialog asking about file naming, etc. Now, however, clicking Import bring up this:
    Never saw this black horizontal dialog box before this situation arose. I was able to import but not as usual and I would like to get back the square (moreso at least) "white" dialog box. No clue what's going on or how to get bact to familiar ground. Ideas?

  • Call stored procedure in JDBC passing Array parameters

    Hi all,
    Im trying to call an Oracle Stored Procedure with JDBC. The problem is
    that my parameter is an Array (PL/SQL Type is "Table Of").
    How can i call this procedure by passing right Java parameters to
    the Callable statement ??
    In the Documentation, all samples don't work ! it's possible to
    call a procedure that return Array Type but when we need to pass an Array as
    a parameter we have a DataType exception.
    Any idea ?
    thanx in advance
    Sam.

    Hi Sam,
    I don't have an answer to your question, just some suggestions as to
    where else you may find help.
    Do you know about the "Ask Tom" website:
    http://asktom.oracle.com
    Also, you may find something in the comp.databases.oracle.* newsgroups:
    http://groups.google.com
    I found this article there -- but it's not exactly what you're looking
    for:
    http://groups.google.com/groups?q=array+group:comp.databases.oracle.server+author:Thomas+author:Kyte&hl=iw&as_qdr=w&selm=a9sg06027kf%40drn.newsguy.com&rnum=1
    Good Luck,
    Avi.

Maybe you are looking for

  • HOW TO MANAGER APPROVE LEAVE REQUEST AT A TIME MORE THEN TWO

    Hi Experts, This is Kalyan.I am working on ess/mss . How to manager approve four work items at a time . And how to add  Custom Fields in UWL .Can u please help me. Regards, Kalyan

  • How to add an App in iTunes Connect?

    I'm using MagPlus to builld my App with iTunes Connect.. Where do I "Add New App" on iTunes Connect? I have an iOS Develop Account. First screenshot is my homepage in iTunes Connect, 2nd one is their sample page of where I need to be. My page doesn't

  • JSF - Duplicate items in menuBar

    This is the original post: Re: JSF - Duplicate items in menuBar I was wondering if anyone ever figured out why the menu item beans being loaded onto the menuBar twice? I have the same problem. And I also have another problem where the submenu items d

  • Size of the Curves dialog in Ps CC

    Can you increase the size of the curves dialog bix beyond the maximum it scales to when you drag the corner out? I'd like to be able to adjust it more finely.

  • Please help with how to copy CS3 from iMac (Snow Leopard) to MacBook Air (Mavericks)

    I have a 2006 Mac Desktop computer with the CS3 suite on it.  I still have the discs for the suite and would like to move it over to my macbook air.  I tried to just copy the Photoshop file, but that didn't work. Is there an easy way to migrate these