Adding two ResultSets in java

How can we add two resultsets in java ?

screen_simu wrote:
Is it something we can do in java?OP, if you can do it in SQL, that likely would be better. On the other hand, do you mean that want to add the results from two resultsets that might perchance be different? IOW ... if both ResultSets produce the same columns, then a UNION join in SQL:select
    tableA.empl_name,
    tableA.empl_id
  from tableA
UNION
select
    tableB.empl_name,
    tableB.empl_id
  from tableBBut, if you want to select out specific columns from differing RS's, then you might want to do this:
  List<Empl> empList = new ArrayList<Empl>();
  public class Empl {
    private String empl_id;
    private String empl_name;
    private Double empl_wage;
    public void setName(String name) {
      empl_name = name;
// ... etc, other method implementations ...
// ... SQL stuff ...
  String sqlA =
     "select"
    +"    tableA.empl_id,"
    +"    tableA.empl_wages"
    +"  from tableA";
// ... rsA is the ResultSet from the tableA selection
  Empl empl = null;
  while (rsA.next()) {
    empl.setID(rsA.getString(1));
    empl.setWage(rsA.getDouble(2));
    empl.setName(processTableB(empl.getID()));
    empList.add(empl);  // new Empl Object for each employee
  public String processTableB(String id) {
    String name = null;
  String sqlB =
    "select"
    +"    tableB.empl_name"
    +" from tableB"
    +" where tableB.empl_id = ?"
// ... set up PreparedStatement ... using passed in id
// ... process ...
  while (rsB.next()) {
    name = rsB.getString(1);
  return( name );
}Above code untested, but hopefully you get the idea.

Similar Messages

  • Controversy in two ResultSet!!!

    Could anyone please provide me a solution for this problem..
    I've created two ResultSet rs1 and rs2, both are retrieving the data from the same table. Manipulation of rs2 or any kind of processing should affect the rs1. So, if i updating something in the same table through rs2 , so it should affect the entire table . So, for other retrieval of data it should be updated. I've written this code, but it's not working.....
    Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                    ResultSet rs,rs1;
                    rs=stmt.executeQuery("select * from checkdata");
                    while(rs.next())
                        String s1=rs.getString(1);
                        int count=1;
                        rs1=stmt.executeQuery("select phone_no from checkdata where phone_no='"+s1+"'");
                        while(rs1.next())
                            if(!(rs1.isLast()))
                                count=count+1;
                                rs1.deleteRow();
                            stmt.executeUpdate("update checkdata set count='"+count+"' where phone_no='"+s1+"'");Please help me out!!!!
    in advance thanks a lot....

    First of all i've this sample_log.txt file which i've putted into the table using bulk insert command . The text file looks like:
    123:books:java:Tue Dec 24 10:34:56 IST 2006
    123:books:java:Wed Dec 25 16:45:58 IST 2006
    123:books:java:Fri Dec 27 10:34:12 IST 2006
    234:books:C++:Mon Mar ..............................
    etc. it's a log file so it just added into the text as the request comes.
    Now i've putted all these values into the table.
    What i want is to read all these details and update the details as the last accessed. Suppose in this example, there should be only one entry for '123' and also update the details as the latest time that is 'Fri Dec 27 10:34:12 IST 2006' rest the two(2) should be deleted from the database and also there should be one more coloumn name count which is to be incremented as it encountered the same no. i.e '123' else it should be 1. The result i want is:
    after putting the logic it should appear as:
    123:books:java:Fri Dec 27 10:34:12 IST 2006:3
    234:books:c++:Mon Mar 12 10:12:10 IST 2006:1
    etc......
    I've to do all this in my jsp page using jdbc connectivity, with SQL 2005 as database.

  • Two resultset objects

    IS it possible to define two resultset objects with two different queries inside the same DB class?java.sql.SQLException: Invalid state, the ResultSet object is closed.
         at net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:299)
         at net.sourceforge.jtds.jdbc.MSCursorResultSet.next(MSCursorResultSet.java:1123)
         at DB5.getDetails(Daily_Quote_Response_report.java:238)
         at Daily_Quote_Response_report.main(Daily_Quote_Response_report.java:74)
    java.util.List items = null;
            String query;
            String query2;
            try {
                query =
                       "select * from oqrep_except_resp_summary";
                query2 = "select * from oqrep_except_resp_detail";
                Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_READ_ONLY);
                ResultSet rs = state.executeQuery(query);
                ResultSet rs2 = state.executeQuery(query2);
              //cannot create two rs objects // ResultSet rs2 = state.executeQuery(query);
                items = new ArrayList();Edited by: bobz on 03-Dec-2009 11:16
    Edited by: bobz on 03-Dec-2009 11:16

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

  • [svn:bz-trunk] 10059: update two package-info.java files, and add one new one.

    Revision: 10059
    Author:   [email protected]
    Date:     2009-09-08 11:31:48 -0700 (Tue, 08 Sep 2009)
    Log Message:
    update two package-info.java files, and add one new one.
    Modified Paths:
        blazeds/trunk/modules/proxy/src/flex/messaging/services/http/proxy/package-info.java
    Added Paths:
        blazeds/trunk/modules/core/src/flex/messaging/util/concurrent/package-info.java
        blazeds/trunk/modules/core/src/flex/messaging/validators/package-info.java

    Revision: 10059
    Author:   [email protected]
    Date:     2009-09-08 11:31:48 -0700 (Tue, 08 Sep 2009)
    Log Message:
    update two package-info.java files, and add one new one.
    Modified Paths:
        blazeds/trunk/modules/proxy/src/flex/messaging/services/http/proxy/package-info.java
    Added Paths:
        blazeds/trunk/modules/core/src/flex/messaging/util/concurrent/package-info.java
        blazeds/trunk/modules/core/src/flex/messaging/validators/package-info.java

  • Adding binary numbers in java please help!!

    Hello all, im a total newbie to java and i need your help urgently, i have two variables
    that are integers, that store binary numbers i.e.
    int tmpIntOne, tmpIntTwo;
    tmpIntOne = 1010;
    tmpIntTwo = 1110;
    i want to add these numbers together and return a binary result so far when you add them together you get:
    2120
    however i would like a binary result so that
    result = tmpIntOne + tmpIntTwo;
    = 11000
    Thank you.

    Hello all, im a total newbie to java and i need your
    help urgently, i have two variables
    that are integers, that store binary numbers i.e.
    int tmpIntOne, tmpIntTwo;
    tmpIntOne = 1010;
    tmpIntTwo = 1110;These are not binary numbers. These are decimal numbers whose digits consist of ones and zeros. If you want to interpret the characters "010" as a binary number, then do
    int tmp1 = Integer.parseInt("1010", 2);
    etc.
    i want to add these numbers together
    int result = tmp1 + tmp;
    and return a
    binary result Adding two ints will give an int. Int's are always binary. If you want to display it as a binary String, as opposed to the usual decimal String, then, as suggested, use toBinaryString.

  • ??how to compare two resultsets??

    hi all!
    i need to find out whether two resultsets contain the same data.
    the only way i know how to do it in java is to put them into a while loop and fetch the contents first and then compare the contents.
    but is there an easier way to compare resultsets?
    does anyone know how to compare two resultsets without extracting the data?
    the code example here executes two identical queries on an oracle database, compare and print the resultsets.
    public ResultSet getResultset(String query)
    ResultSet rs=null;
    try { rs=Stmt.executeQuery(query); }
    catch(Exception e) { e.printStackTrace(); }
    return rs;
    public static void main(String[] args) {
    ResultSet r1=null;
    ResultSet r2=null;
    try {
    database db = new ddatabase();
    r1=db.getResultset("Select 'name' from person");
    r2=db.getResultset("Select 'name' from person");
    if (r1 == r2) {
    System.out.println("ok");
    System.out.print(r1);
    System.out.println();
    System.out.print(r2);
    else {
    System.out.println("not ok");
    System.out.print(r1);
    System.out.println();
    System.out.print(r2);
    jdbc.cleanup();
    catch(Exception e) {e.printStackTrace();}
    and here is the output:
    F:\java rs_compare
    not ok
    oracle.jdbc.driver.OracleResultSetImpl@4413ee
    oracle.jdbc.driver.OracleResultSetImpl@786e64
    as you can see the resultsets are different though the data they contain have to be the same.
    so the 'if(resultset#1 == resultset#2)' does not work.
    thanks for any help
    best regards
    5ithl0rd

    Don't cross-post.
    I'll bet ResultSet implementations don't override equals() to provide "deep equals" behavior, in which case it'll be no different than using "==".
    It's a bad idea to compare two ResultSets this way. You'll have to load both into objects or data structures and compare those in a "deep" way.
    Besides, the ONLY way two ResultSets could be different, given the same query, would be if there were multiple clients that could write to the table between queries and change the underlying data. If your two queries are sufficiently isolated, I'd say that the same query will return the same ResultSet.
    %

  • Comparing two ResultSets for equality

    Hello,
    I wish to test if two separate ResultSet objects are identical.
    By identical I mean that two different ResultSet objects are identical if
    they contain the same rows in the same order, and each row contains identical values in the two ResultSets.
    Two possibilities could be that the equals() method returns true or that the hashcode() method also produces the same hash value if the objects are identical as described.
    I haven't been able to find any documentation on this issue.
    Does anyone know if either (or both) of these methods have the contract as described above? If so are they guaranteed?
    I can see several potential problems here. Performance with a large ResultSet, duplicate rows, and the ordering of rows not being guaranteed?
    Thanks in advance.
    Tim

    Two possibilities could be that the equals() method
    returns true or that the hashcode() method also
    produces the same hash value if the objects are
    identical as described.I can tell you without looking anything up that these methods do not do that, as doing that would require them to scan the entire result-set, and JDBC tries to avoid doing useless processing. You are going to have to write this code yourself.

  • Comparing two ResultSet

    Hi Everybody,
    Can anybody tell me is there any method to compare the contents of two ResultSets and decide whether they are same or not.
    Thanks

    Yes,
    Create a method that takes the two result sets, get the metada of the table and compare field by fiel.
    Another alternative is to copy the ResultSet to a Vector and than compare it.
    HTH
    Trajano Roberto

  • How to compare two files in java & uncommon text should print in text file.

    Hi,
    Can any one help me to write Core java program for this.
    How to compare two files in java & uncommon text should print in other text file.
    thanks
    Sam

    Hi All,
    i m comparing two HTML file.. thats why i am getting problem..
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class textmatch{
    public static void main(String[] argv)
    throws Exception{
    BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
    BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
    String s;
    String y;
    while ((s=fh.readLine())!=null)
    if ( s.equals(y=sh.readLine()) ){    
    System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
    sh.close();
    fh.close(); }
    thanks
    Sam

  • How to compare two files in Java & uncommon text should print in Diff text

    Hi All,
    can any one help me to write a java program..
    How to compare two files in Java & uncommon text should print in Diff text file..
    Thanks
    Sam

    Hi All,
    i m comparing two HTML file.. thats why i am getting problem..
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class textmatch{
    public static void main(String[] argv)
    throws Exception{
    BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
    BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
    String s;
    String y;
    while ((s=fh.readLine())!=null)
    if ( s.equals(y=sh.readLine()) ){    
    System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
    sh.close();
    fh.close(); }
    thanks
    Sam

  • I accidentally added two .doc files, they show in iTunes file sharing, but don't show on iPad?

    I accidentally added two .doc files by dragging and dropping into itunes, under my device, then the app tab, then file sharing for Adobe Reader, they show in iTunes file sharing window, but don't show on iPad 3, and I cannot delete them on iTunes screen? Please help!

    First, I would advise you to apply Tao philosophy to this. Given the dysfunction of most software, if this was just an accidental copy and you don't want them on iPad and they are not showing up anyway, what's the problem? Forget it. It's not worth the hassles. I'm more concerned that you have psychological issues you need to be dealing with, not this. You are making much too unnecessary work and stress for yourself.
    As for deleting them, I'm assuming you highlighted them and hit delete and it didn't work. If not, it should. Works for me. But if it doesn't, my advice is also not to worry about it, as annoying as the clutter is. It will eventually resolve itself (like when your data files corrupt or your iPad crashes, LOL. (I apologize for my cynicism but I am fed up with dysfunctional software). It's not worth the hassles of trying to figure out petty issues.
    As for me, I have the opposite, and very serious problem. I've got Reader on my iPad too. But I can't move the pdfs out of it and onto my laptop with iTunes' dysfunctional file sharing. I get the error "file cannot be copied because you do not have permission to see its contents." I have hundreds of pdfs on my iPad that I converted from web surfing with other programs that also don't work and I can't get them off the iPad for backup and to have a synced library I can access from both laptop and iPad.
    I called iTunes twice and both times they blamed it on the app, saying iTunes file sharing doesn't support third party apps and that I should call Adobe and talk them into writing the code that will work with iTunes. Yeah, right. And Reader is not the only problem. This is happening with iAnnotate and Write PDF and other apps.
    I suspect that both of us have the root problem, perhaps Apple's greedy refusal to support the apps that it sells in the app store and are quasi-integrated enough to show up in the file sharing documents list, but can't be moved or deleted; and the apps that don't bother to make their apps fully work with iTunes file sharing.
    If anyone has any solutions ......

  • Query a resultset in java like CFQUERY

    Hello,
    Is there a way to query a resultset in java. Yes what I mean is after obtaining one resultset, again query on that resultset like we do to a table in the DB.
    Here is my problem in detail and any help doing the same in Java will be most appreciated :-)
    I am working on a peculiar problem where we are moving our application from cold fusion to Java. Cold fusion being very powerful for database oriented applications my project was initially developed using CF and uses a lot of advanced features of CF. However the need to move to java was soon realised due to various reasons. Now one of the main problems we are facing is the CFQUERY tag in cold fusion.
    This tag lets you create a resultset by
    <cfquery name="aaa" datasource="blah-blah">
    QUERY COMES HERE
    </cfquery>
    The best part is.... you can also query the above resultset obtained as follows:
    <cfquery name="bbb" dbtype="query">
    SELECT * from aaa where ***************
    </cfquery>
    We have used it so often in CF since it significantly reduces the query throughput times. Now we would love to find a way to do the same in Java.
    Any ideas
    Thanks
    Karen

    Yes thats one way of working with it. But the problem
    is we are dealing with very huge volume of data and
    hence querying an already existing resultset is the
    best option and has been working very well with our
    kind of project too. We also have several concurrent
    users doing the same which adds more load on the DB so
    doing it from the CF/Java end seems a better choice
    for us.I understand your sentiment, but having worked with applications trying to 'port' applications to new technologies I would have some concerns with your approach. Rather then 'port' the application I would suggest that you will have to re-engineer the application. This is more true for larger systems where larger system is heavy mulit-user, or large database access. It is also more true for applications moving from procedural to object based languages.
    I don't agree that you are better off manipulating data on the application server. In my experience I have found that data manipulation is optimized when running as close to the database as possible (for the reasons listed in my previous post). So if you decide to re-engineer you may want to consider this in your design decisions.
    We already have the DB so we are not even considering
    looking for another one. BTW we're using SQL SERVER.Well, as long as you don't have too many users (darn that original sybase lock manager) :-)
    I too can't think of a way to get this done using Java
    like CF. Hmmm .... yeah if nothing else then we'll
    have to change the way we work all together.I have no experience in using it, but user "cluckcluck" posted the following. Might be something to take a look at. This is similar to what I was talking about when using embedded Java databases like Cloudscape, but this works with external databases:
    "An excellent solution for this sort of problem is Hibernate (www.hibernate.org) a DB independent ORM persistance layer. Each data source would need to be defined, and each datasource would have its own SessionFactory but once this mapping and config is done you can treat the contents of the DB as POJOs, and perform queries against them. Its not so generic that you wouldn't still have to know which data model the entity you are after is in..."
    Good Luck!

  • Problem araised in  adding two custom fields to ksb1 tcode.

    hi experts,
      I added tow fields vendor no, vendor name to Tcode:KSB1.
    i used user-exit :   coomep01 .
    in this exit i added two fields to ci_rkpos (include table) . i.e zlifnr,zname1.
    but that problem is ci_rkpos is not appearing in green color it means it is not transported .
    in development  client is working properly .
    using sm34 i added fields names.
    error is coming like this.
    The following syntax error occurred in the program SAPLXKAEP :
    "The data object "CS_RECORD" has no component called "ZLIFNR", but ther"
    Error in ABAP application program.
    The current ABAP program "SAPLKAEP" had to be terminated because one of the
    here wat ever we add the zfields will appear in kaep_coac ,so in this structure two added fields are appeared in dev client
    but,the same zfields when transported to quality is not appearing .
    please suggest how to do??

    hi breakpoint.
    yes i attached  in transport.
    in quality client.
    wat ever i wriiten code  in user exit it is coming ,but
    incldue table structure is not coming ,and even that fields are appearing in v_tkalv ,but in structure kaep_coac
    blank include strcuture CI_RKPOS is appearing ,but
    in dev client is working properly, and in quality first of all report is going to dump.
    here this tvode is using all 3 plants,how can i restrict to specified plant so that ,it will not affect others plant.
    suggest me how to do??
    Edited by: kamalsac on Aug 18, 2010 10:57 AM

  • Adding two leading zeroes infront of a variable(both character and numeric)

    Hi Experts,
    I have a variable v_data. Whatever is the value of the v_data, two leading zeroes should get added to it.
    v_data may be numeric or charachter type.
    I am using FM CONVERSION_EXIT_ALPHA_INPUT for adding two preceding zeroes for numeric types but for character types what logic I should use?
    Currently I am doing:
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input         = v_data
    IMPORTING
       OUTPUT        = v_data.
    if v_data CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
        SHIFT v_data BY 2 PLACES right.
        v_data+0(1) = '0'.
        v_data+0(2) = '0'.
    endif.
    But the above code is giving output like this: 0 P0001 but I want output like 00P0001.
    How to fix it?
    Regards,
    Sangeeta.
    Edited by: Sangeeta on Nov 11, 2008 6:22 AM

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
    input = v_data
    IMPORTING
    OUTPUT = v_data.
    if v_data CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
    SHIFT v_data BY 2 PLACES right.
    v_data+0(1) = '0'.
    v_data+1(1) = '0'.   " change this
    endif.

  • Running two versions of java, is it possible?

    Hi everyone, I've got two applications, both incorporate applets, but one uses 1.3 and the other uses 1.4. Im stuck as I need to run these two programs at the same time. The reason I cant just use 1.3 is because one uses JTree's which were introduced in 1.4 (am I correct?) . SO if thats the case, is there anyway to use two versions of java on the same machine.????????????
    Thank you
    Graham

    I've got two applications, both incorporate appletsYou have two applets.
    one uses 1.3 and the other uses 1.4. One requires at least 1.4 (you think)
    I need to run these two programs at the same time.
    The reason I cant just use 1.3 is because one uses JTree's which were introduced in 1.4 (am I correct?) .The 1.3 API Spec includes JTree
    So if thats the case, is there anyway to use two versions of java on the same machine?Why can't you just use 1.4

Maybe you are looking for

  • How to get the total no of delivery quantity in PO

    Hello, This is shehryar. my previous account got locked(dunno why  ) , so i have created a new acc. I want to display the total no of delivery quantity of a line item in PO. can it be done ? Thanks.. Shehryar

  • From user option in import utility

    hi, i am using oracle 10g(10.2.0.4.0) and i have exported two tables from different schema and created a dump file. Now i am trying to import those two tables into the same schema in single import command. Is that possible???? can i give both the use

  • Network install from solaris 10 x86 server to x86 client

    My setup is: install server OS: Solaris 10, i86pc . The install server is also boot server using tftpboot. The dhpc server is configured according to the instructions which are given when adding an install client in Solaris 10. The client can communi

  • Notification Email For Due Date.

    Hi all, I would like to seek help from you all guys in this scenario. I have a table with a column "due_date", I want my application to automatically send email to the end user when the sysdate is 1 day before the due date. What should I do,please ad

  • No horns in garageband for ipad 2?

    Where are the horns in garageband for the ipad?