Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Tolls

Thread: methods available

  1. #1
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default methods available

    Is there any method available in REsultSet class that will enter the entire column as a array of string.
    For example if the resultset obtained contains 2 columns and 5 rows is there any method available to get only the values available in the first column. That is it need to return the 5 values of first column.?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: methods available

    No.
    ResultSets are simply a cursor which points at a row in the result.
    You'd either have to change your query to return the data in that format, or iterate over the results and concatenate the data in Java.

    If you only want the values form the first column then I would question why you have a query that returns data from column 2 as well.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: methods available

    I wanted to display it like that to the user.. All the column one first and then two . I did that by moving the cursor of the resultset and then storing it in a String .

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: methods available

    So two Strings you concatenate together.
    Actually, two StringBuilders, hopefully.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: methods available

    I will check out about StringBuilders i am not sure about that

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: methods available

    If yo have this code (as an example:
    Java Code:
    String myString = "";
    for (String aString : myListOfStrings) {
        myString += aString;
    }
    Then the compiler will create a StringBuilder each time round that loop in order to do the '+='.
    WHereas:
    Java Code:
    StringBuilder myString = new StringBuilder();
    for (String aString : myListOfStrings) {
        myString.append(aString);
    }
    uses the single StringBuilder you created.
    mkarthik90 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Java Noob, trying to call methods from another methods
    By gabrielpr12 in forum New To Java
    Replies: 8
    Last Post: 11-17-2011, 09:07 PM
  3. Replies: 1
    Last Post: 10-23-2011, 12:37 PM
  4. Replies: 1
    Last Post: 10-05-2011, 12:15 AM
  5. Replies: 4
    Last Post: 04-03-2009, 06:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •