Getting size of ResultSet Object

Is there any effective way to retrieve the size of ResultSet object while the type of the ResultSet itself is a default one (TYPE_FORWARD_ONLY) ?

Maybe I was a little harsh ...or lazy to type anything. I don't think there are any efficient ways to count the number of rows in a ResultSet(for scrollable, forward only, etc)
You could do the following:
rs= statement.executeQuery("select count(column1) from table1 where column1<100");
rs.next();
long recordCount = rs.getLong(1);
before executing your real query
rs = statement.executeQuery("select column1 from table1 where column1<100");
while rs.next.....
Jamie

Similar Messages

  • How get size of grafical object?

    I load object from *.wrl using loader. I want get size of this object. How do it???

    Hello,
    The method I use is the following:
    - Find all Shape3D objects within your loaded scene.
    - For each Shape3D object extract it's bounds with:
    BoundingSphere bSphere = (BoundingSphere)Shape3D.getBounds() ;
    - Extract the bounds radius with:
    bSphere.getRadius() ;
    You can also do this with a BoundingBox for more accuracy.
    Remember, though, that the "size" is completely arbitrary, unless you know the measurements and scaling used in the original scene.
    Hope this helps,
    Shawn

  • How to set the fetch size for a ResultSet object?

    Connection con  = getConnection();
    Statement stmt = con.createConnection();
    ResultSet res = stmt.executeQuery("select * from table");
    //res.setFetchSize(?);
    while (res.next)
    res.get....
    }I do not know the number of rows .
    How can I set the fetch size for the ResultSet object?
    I try
    res.last();
    res.setFetchSize(res.getRow()/2);
    res.beforeFirst();
    while (res.next)
    res.get....
    }but it's so slow if there are 6000 rows.
    How can I set the fetch size for the ResultSet object more effectible?
    And what is the best number to set the fetch size?

    The fetch size defaults to a standard number. It is unlikely that it will be any faster if you set it unless you only plan to read a small number of rows.
    i.e. if you are going to read all the rows, you need to read all the rows no matter what.
    Unless the system has set the fetch size to 1 changing it will not be faster.
    Depending on the row length, reading in 6000 rows is going to take a long time. You could try using a cpu profiler to improve performance.
    Do you really need to read everything in every row?

  • How to get a size of a object

    Hi
    Anybody Knows how to get a sizeof a object in java,
    Pls reply to this.
    cheers,
    Sen

    That's a bit ambiguous...
    If you are asking about the size of the object reference in memory, then it is defined in the JVM specification.
    I suspect you are asking about how much memory a given object takes up - that's going to be a bit tricky, because objects point to other objects, etc...
    Rather than trying to come up with a solution to the question, I'd like to ask exactly why you need this - that might help the forum to come up with a solution to the real problem. Sound good?
    - K

  • Howto get RowCount of ResultSet

    Hello,
    is there an intelligent way of getting the rowcount of an resultset?
    For now I execute 2 SQLQueries, where the second is just executed to get the amount of rows in this selection, which is a lot of sumb overhead:
    ResultSet rs = db.getStatement().executeQuery("SELECT * FROM BOOKS WHERE LOWER(titel) like '%" + searchStr + "%' OR LOWER(autor) like '%" + searchStr + "%' OR LOWER(instrument) like '%" + searchStr + "%' ORDER BY " + orderTableName + ";");
                   ResultSet countSet = db.st2.executeQuery("SELECT COUNT(*) FROM BOOKS WHERE LOWER(titel) like '%" + searchStr + "%' OR LOWER(autor) like '%" + searchStr + "%' OR LOWER(instrument) like '%" + searchStr + "%';");
    Any ideas howto do this in a better way?
    Thank you in advance, lg Clemens

    [Standard pre-packaged copy&pasted rant follows]
    The really really best way to know the number of rows in a ResultSet: write your application so that you don't need to know it.
    To get the number of rows in a ResultSet, loop over the result set with while(res.next()). Read each row into an object. Add each object into e.g. a LinkedList. At the end, you will have the rows nicely converted to objects (which you usually should do anyway). And list.size() will give the number of objects.
    There are other ways to get the number of objects, but list.size() is the easy and reliable way. If you don't need the rows converted to objects ...why did you select them in the first place?
    Tricks with last()/getRow() sort of work. They read the entire result set into memory (in a memory-inefficient way: the storage that scrollable result sets take is almost certainly more than "real" objects). But you'll need to write the while(res.next()) loop anyway. No point in having the computer do the same thing twice. So last()/getRow() is inefficient and just plain extra silly work.
    Still thinking of using last()/getRow()? Bad idea. When you execute a select, the database server doesn't necessarily even know the number of rows you selected (the cursor "materializes" as it is being read). The server will hand rows to the JDBC driver, without being able to tell in advance how many there will be. So the only way getRow() can know how many rows there are is by reading in all of the rows. This consumes time and memory. And you STILL have to write the while(res.next()) loop, so the computer is doing the same work twice and you are writing extra code.
    "select count(*) from ..." is another way, but it has a few problems: (1) The query gets executed twice, so it is almost twice as slow. (2) The number of rows can change between the two queries. (3) You'll need to write the while(res.next()) loop anyway, so you'll be doing silly useless extra coding work.
    Best Practice: stop needing the number of rows.
    Second Best Practice: while(res.next()), create objects, put into a LinkedList, use list.size().
    Silly Extra Work And Slowness: last()/getRow() or select count(*).
    There may be situations where last()/lastRow() may be reasonable. You need to know how your database implements them and understand the performance implications. Don't even try if you can at all use the better ways.
    There is a related question: how do I page database results. That may require "select count(*)" or something, depending on how you want to do it. There is no really perfect universal solution for that question using plain SQL.

  • Scrollable/Read_only  ResultSet objects

    I am trying to create an instance of a scrollable/read_only ResultSet object with the following code:
    Statement stmt = con.createStatement(
    ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = stmt.executeQuery("SELECT * FROM ...");
    The Connection object has been made successfully but am getting an AbstractMethodError Exception at line 1.
    Can anyone please help me out here.
    Thank you.

    I don't believe the Oracle driver allows for
    read/only. I'll take a look at the Oracle website,
    and see if I can verify that.
    JoelSorry, I was wrong on this. From the Oracle JDBC documentation, it states that CONCUR_READ_ONLY is valid for the Oracle 8 and Oracle 9 drivers. Are you using classes12.zip or classes12.jar for your Oracle libraries?

  • Scrollable/Updateable ResultSet objects

    I am trying to create an instance of a scrollable/updateable ResultSet object with the following code:
    Statement stmt = con.createStatement(
    ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stmt.executeQuery("SELECT * FROM sch.a");
    The Connection object has been made successfully but am getting an AbstractMethodError Exception at line 1.
    Can anyone please help me out here.
    Thanks
    I am using JDK 1.3.1 and JDBC 2.0

    I use this and works fine for me....let me know how it goes...
    ResultSet resultSetMultCond = null;
    Statement getMultPartCond = null;
    String sqlMultCond = null;
    sqlMultCond = "SELECT #PART,#CONDS,COUNT(*) AS MCOUNT FROM MYLIB WHERE #PART = 'A123' GROUP BY #PART,#CONDS ORDER BY #PART";
    getMultPartCond = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
    resultSetMultCond = getMultPartCond.executeQuery(sqlMultCond);

  • What's with the slow gets from my ResultSets?

    I have two databases, an Omnis and a MySQL. I'm trying to copy the data from the Omnis into the mysql, but the getXXX(int i) methods acting on my ResultSet are LUDICROUSLY slow... to transcribe a meager 2660 entires (with 15 columns) takes a staggering 25.3 minutes! Now, what's interesting here is Microsoft Access can have the data in about 3 seconds. Same thing applies when moving from MySQL to access or one MySQL database to the other.
    I am forced to assume that the problem lies with the ResultSet object that the JDBC:ODBC bridge that I'm using to access Omnis from Java. It's also confirmed that the culprits are the get methods, as I can iterate through the entire ResultSet with successive calls to rs.next() and get all the way through it in a couple seconds so long as there are no getXXX() methods in the while loop. Is this problem surmountable? What gives? O_o
    thanks in advance.

    It's not the JDBC-ODBC bridge either... as I can pull data from Omnis > Access > MySQL in about 1/1000th of the time it takes me to go from Omnis > MySQL.

  • Determine the Size of an Object in ObjectInputStream

    Hi all,
    I have a quick question. I have a class that is being written over a socket using ObjectOutputStream and ObjectInputStream. I want to be able to set the buffer size of the socket to fit only ONE object. Can anybody tell me how to determine the size of that object?
    (Note, the object has a Properties object within it, but for the time being, it can be assumed that properties object will always be the same.)
    - Adam

    Having written it to the outputStream, thought, can
    the size be determined somehow by the inputStream?No, it can't
    This is related to my previous question (on Pushlets
    and Thread Priorities). I didn't read that one.
    I believe that it's possible
    that multiple threads are trying to write to the
    socket at the same time, and I cannot synchorize the
    input stream to get a lock on it. Do you mean the outputstream? Why can't you synchronize the method that writes to the outputstream?
    I thought this
    might be causing the data to not be sent over the
    socket until all the threads have finished. That doesn't sound correct. But you could call the flush method when an object is written.
    I
    figured if I reduced the size of the socket buffer,
    it would only accept a single object, eliminating
    this problem?I don't think so.
    /Kaj

  • How can I get a count of objects in the near cache? (Extend client)

    Hi,
    I'm trying to figure out how to get the count of objects in my near cache (from c++ client). Knowing the size of the near cache is a key factor when optimizing configurations for performance.
    However if I call size() on the cache handle I get the count of objects in the cache (ie the cluster). How can I get a count of objects in the near cache?
    Thanks
    Rich Carless

    H Rich,
    It may not be ideal, but I think you may be able to infer the size by using the HeapAnalyzer (http://download.oracle.com/docs/cd/E15357_01/coh.360/e15728/classcoherence_1_1lang_1_1_heap_analyzer.html) facility, specifically the "class" based HeapAnalyzer. Its Snapshot representation http://download.oracle.com/docs/cd/E15357_01/coh.360/e15728/classcoherence_1_1lang_1_1_class_based_heap_analyzer_1_1_snapshot.html provides a mapping between class name and ClassStats (http://download.oracle.com/docs/cd/E15357_01/coh.360/e15728/classcoherence_1_1lang_1_1_class_based_heap_analyzer_1_1_class_stats.html) which provides information on how many instances of a given class type are in memory. Note the reported counts are process wide but if your key or value type are distinct you may be able to infer your answer. I realize this is rather complex, my only other suggestion would be to just make some guesses on size and see how they effect performance.
    Mark
    Oracle Coherence

  • How to find size of ResultSet in JAVA

    hi ,
    I have one problem... went for sun API but i did not get any solution....please any body help me... my problem is ......
    I got the data from DataBase by executing a query . so my Resultset having some records.Now my problem is how to find the size of ResultSet.without converting into list or without wile loop I want to find out size of my ResultSet
    ..... Is there any predefined method for that;
    thanks in advance

    gbabu wrote:
    hay.... again you are diverting from topic. my problem is how to find resultset size.... not for how to write query for counting records.Of cousre he is. Because the answer to your question is: it can't be done. So he's kindly moved on, and offered you an alternative way to achieve what you want. If that offends you, I suggest you have your head in an uncomfortable and unsuitable orifice
    Why are you so desperate to know the size of the ResultSet anyway? If you've got limits on the size of ResultSet that's acceptable, you can adjust your query to limit the number of rows returned. if you simply need to know how many rows there are, pulling the entire content of the table(s) back and counting them afterwards is horrifically inefficient. If you need to know to so you can prepare a datastructure to put the results in, maybe you've chosen the wrong structure (I'm thinking 'array' here). You might have a legitimate reason to find out the size of a ResultSet, I don't know. But the ResultSet interface doesn't give you that option, so you're on a hiding to nothing, and might as well use the suggested alternative, or reconsider your requirement

  • Size of user objects

    Hi *,
    I have a question concerning the size of all objects owned by a user. I tried to figure this out with several methods:
    1. rman: one fullbackup ca. 64 GB
    2. size of datafiles - free space: 35 GB
    3. export: 15 GB
    Why do I get these big differences?
    regards
    Andreas

    Export extracts only rows tables and DDL for objects. Indexes "data" are not exported.
    You tablespaces are (hopefully) not full: the free space is likely not backed by by rman.
    Message was edited by:
    Pierre Forstmann

  • # of objects, not the size of the objects, determine size of a Collection

    There are objects, and references to objects.
    Do, List / Set / Map , etc. just maintain a list of 32-bit addresses for their contained objects? What more does a Collection need, memory-wise, to add an element? The size of the objects in a Collection should not matter?
    listA.add(new Integer(2));  // listA size grows by 32-bits
    listB.add(new GiantSizedClass());  // listB size grows by 32-bitsI started thinking about Collections being able to dynamically grow in runtime. I heard this is complex, but it "looks" like all you do is append a memory address and incriment a counter? This sounds quick, easy, and incorrect. I don't understand. Thanks.

    jverd, ejp: you have always been there with quick responses to help me. ejp, i purchased your book "Fundamental Networking in Java". When I start programming again, your book about RMI is on my list. that said.
    with all sincerity. i belived that serliazing objects in byte[] allows for storing objects in objects, not object references in objects. here is my test code (just cut/paste):
    My idea seems similars to me as cryogenics and so that is the theme of my test code (and it is my favourite movie). note: this code is "proof of concept" and is exetremely hacked together.
    public class Test {
      private static HashMap<String, byte[]> barracks = new HashMap<String, byte[]>();
      public static void main(String[] args) {
        try {  new Test().go();  }   catch(Exception e) {  e.printStackTrace();  }
      public void go() throws Exception {
        Employee empl = new Employee("Dallas", "Captain");
        barracks.put(empl.name, cryogenicallyFreeze(empl));
        empl = new Employee("Kane", "Navigator");
        barracks.put(empl.name, cryogenicallyFreeze(empl));
        empl = new Employee("Ripley", "First Officer");
        barracks.put(empl.name, cryogenicallyFreeze(empl));
        empl = new Employee("Ash", "Science Officer");
        barracks.put(empl.name, cryogenicallyFreeze(empl));
        System.out.println("___log file___");System.out.println(".........");
        int id = (int) (System.currentTimeMillis() % barracks.size());
        System.out.println("[Nostromo]: emergency id #"+id+". Re-animation initiated...");
        switch (id) {
          case 0: empl = (Employee) reanimate("Dallas"); break;
          case 1: empl = (Employee) reanimate("Kane"); break;
          case 2: empl = (Employee) reanimate("Ash"); break;
          case 3: empl = (Employee) reanimate("Ripley");
        System.out.println("[Nostromo]: \"" + empl.name + "\" in command.");
        System.out.println("["+empl.name+"]: Hello. I was an object, not a reference, stored in a collection.");
        System.out.println();
        public static Employee reanimate(String name) throws Exception {
            PipedOutputStream pout = new PipedOutputStream();
            PipedInputStream pin = new PipedInputStream(pout);
            byte[] frozenEmpl = (byte[]) barracks.get(name);
            pout.write(frozenEmpl);
            ObjectInputStream ois = new ObjectInputStream(pin);
            return ((Employee) ois.readObject());
        public static byte[] cryogenicallyFreeze(Employee emp) throws Exception {
            PipedOutputStream pout = new PipedOutputStream();
            PipedInputStream pin = new PipedInputStream(pout);
            ObjectOutputStream oos = new ObjectOutputStream(pout);
            oos.writeObject(emp);
            byte[] frozenEmpl = new byte[pin.available()];
            pin.read(frozenEmpl);
            return frozenEmpl;
          public static class Employee implements Serializable {
            String name; String title;
            Employee(String n, String t) {  name = n; title = t;  }
    }"inside" of each byte[] object is an "Employee" object? I can't see it any other way. But I am not the sharpest pencil in the drawer...I'm on vacation from coding for a while. maybe i will get it when i start again. thanks.
    Edited by: rdkh on Jan 29, 2010 3:53 AM

  • CRM - Modifying block size of Adapter Object (R3AC1)

    Hi,
    We have differences between SAP R/3 and CRM systems. Not all the business parters are in sync between two systems. In order to bring business parter tables in sync, we are executing R3AR2/R3AR4 for a range of 10,000 BPs at a time.
    My question is, we are doing this by with the block size of adapter object BUPA_MAIN to 1.  This is resulting into creation of 1 queue per business parter. Is there any harm with keeping the block size to 1 ?
    We attempted to do it with block size 100 but for some reason, it's not working fine. With block size 100, not all the BPs from input range are getting selected for replication.
    Thanks,
    Amol

    Hi Amol - For the MATERIAL ADAPTER we are using MARA-MTART criteria, but also want to apply MARC-WERKS.
    In order to stop the entire MATERIAL record from being downloaded, we used BTE OPEN_FI_PERFORM_CRM0_200_P and wrote a function module to interrogate the MARC table for the MATNR.
    If the MATNR was not extended to a specific PLANT, then the record was not downloaded to CRM.
    However, I discovered that with the MATERIAL BLKSIZE = 100, there were some records that did not meet the criteria slipping through to CRM.
    So I made the BLKSIZE = 1, and the correct filtering is occurring!  I'm not sure why, but I suspect there is something in the CRS_SEND_TO_SERVER function module in ECC, that is not looping properly.  And it works just fine when there is just one record at a time.

  • Deep Cloning of resultset object

    Hi, Is it possinble? Deep Cloning of resultset object?
    Resltset rs = pstmt.execute()
    Anyway to assign rs2 = rs1
    Because I am passing my resulset to a legacy application's method, that does a rs.close(). I need to use the same resultset later. JDK 1.4

    Write a dynamic proxy to the ResultSet where theclose() method does >nothing.
    What if the OP discovers that the app does a rs=null
    as well?How can that affect your code? Presumably the ResultSet is passed as an argument to a legacy method so the legacy method might set it's local reference to null it will not affect the reference held by the caller of the method.
    The op then runs thru hoops to get permission to
    modify a line in legacy code and is too distressed to
    post.He does not need to! You need to learn about Java argument passing.
    Anyway, thanks for the classrom solution. but i cant
    create another class file for extending rs.You have not presented any reason why not! This can be an inner class in the code you are writing and has no influence what so ever on the legacy application.
    >
    If you are too distressed by the posts here, you are
    under no obligation to reply to every one. Anyway , i
    found the postI replied because I had a viable solution to a problem you were having. Nothing you have said so far stops it being viable. Look at my posting history - I do not try to reply to everyone.
    >
    A Resultset is mainly a Java front end for adatabase
    cursor (which exists on the database server). When
    the ResultSet is closed, the cursor will be closed
    too so, even if you could copy everything in the
    ResultSet object, the handle for the cursor wouldno
    longer be valid.
    Which is why you use a Proxy so that you can control exactly what happens.
    >>
    To truely "deep copy" a resultset the depth would
    have to extend accros the database connection to
    cloning the cursor.I still don't see why you need to clone the ResultSet rather than use a proxy!
    >
    very much useful than the self pity expressed by
    you.No self pity! I just expressed annoyance at the lack of feedback from you and many others.
    No offence, none taken and none dealt.I still find it offensive when people don't bother with a simple acknowledgement. I don't ask many questions myself but when I do I make sure I track the responses and acknowledge those who try to help.
    I still think you should re-think your solution but you are free to totally ignore my very simple solution. I expect you will ignore it so the best of luck.

Maybe you are looking for

  • Notification Error when using PL/SQL document

    I have a notification that calls a procedure that returns some HTML body of the email. It worked once, but now I get the error below. In Oracle Apps on the notification tab the notification shows correctly, it's the actual sending of the email that i

  • Can't post a new discussion? Oh Yes I can...

    Trying to post a question about an issue I am having and I get a message stating that I am not allowed to edit or post... So I am trying this post here... Need help deciding if the invalid Launch Agents/Daemon could be causing an issue with my MBP. T

  • Create a New Calc Script from VB.

    Does anyone know how to create a calc script using the VB Essbase API? We are going thru a large modification. Most of our calc scripts are stored on an oracle database. The idea is to send the stored scripts to a text file and then using the essbase

  • Ring File Unavailable--Nothing has changed, but now they don't work.

    I'm receiving an error message of "Ring File Unavaible". I have ensured it is converted to 8000hz, mono, 8-bit mu law and all of the variables. My Ringlist.xml is good to go. I am accounting for the use of capital letters. The error is not a bad ring

  • Mp3's copied to phone, wont play

    I have a 6288 with a 2gig memory card, and when i copy songs on to it, some...not all, songs will play part of the way thru, then mysteriously stop and go to the next track. Some songs don't start at all, but the file name and size is on the playlist