Number of columns in a resultset

Hi all,
I would like to know if it's possible to get the number of columns returned by a resultset:
conn = pool.getConnection();
cs = conn.prepareCall("{call server.procedure(?,?,?)}");
cs.setString(1, name);
cs.setString(2, string);
cs.registerOutParameter(3, OracleTypes.CURSOR);
cs.execute();
rs = (ResultSet) cs.getObject(3);
here I would like to know how many columns there are in the resultset, rs.next returns the next row but I need the columns as well.
Thanks,
A.

ResultSetMetaData rmd = rs.getMetaData();
System.out.println(rmd.getColumnCount());

Similar Messages

  • Number of Column In My Resultset ?

    Hi,
    Can I know the numbre of Column in my Resultset ?
    Thanks.

    Yes, ResultSet::getColumnListMetaData() returns metadata information of the columns in the resultset. Each element in the returned vector is a MetaData object for a column, the count() of the vector gives the number of columns.
    -Shankar

  • Number of columns of the rows in a ResultSet?

    Hello
    Is there any way to get the amount of columns of the rows in a ResultSet? The values of the columns might be empty, so wasNull() wont work?
    Thanks

    Yes, you can see the number of columns and lots of other info, see ResultSetMetaData. Example:
    ResultSet rs = statement.executeQuery("...");
    ResultSetMetaData rsmd = rs.getMetaData();
    System.out.println("Number of columns: " + rsmd.getColumnCount());Look it up in the API documentation.

  • Maximum Number of Columns a ResultSet can support

    Hi,
    Can someone tell me what the maximum number of columns a result set can support? I'm using a cachedrowset to retrieve about 50 columns from a table and it seems to stop collecting columns after 33.
    Is there a way to work around this?
    Thanks

    Can someone tell me what the maximum number of
    columns a result set can support? I'm using a
    cachedrowset to retrieve about 50 columns from a
    table and it seems to stop collecting columns after
    33.
    33 is a suspiciously low number.
    Why do you think it 'stopped'? Explain exactly how you determined this.
    What are the data types of fields 30-34?
    Why do you think that the java program is actually getting 50 columns?
    Finally in general everything in a computer is limited. However 33/50 would be significantly below normal limits for most resources.

  • How to get the number of columns in a result set???

    hi everyone..
    i am trying to establish a servlet applet communication....
    my applet send the sql query to the servlet as serialised string and then the servlet executes the query...
    Since i need to pass the result back to the applet, i thaught of passing the whole reult set to the applet..but that seems to be not possible..
    so i thaught of storing my result set data in a vector and then pass the vector,but the first problem that i came across is that how to get the number of colums in a result set....
    so is there a way to get the number of columns in a result set...???
    and also i would like to know if it possible to send my whole result set to the applet bye serialization or by any method...???
    thanx in advance

    You shouldn't do. It expenses resources (you should always close the ResultSet and the Statement as fast as possible). Simply gently process it into a Collection or Map of DTO's. Those are serializable.

  • How do you return the number of Rows in a ResultSet??

    How do you return the number of Rows in a ResultSet? It's easy enough to do in the SQL query using COUNT(*) but surely JDBC provides a method to return the number of rows.
    The ResultSetMetaData interface provides a method for counting the number of columns but nothing for the rows.
    Thanks

    No good way before JDBC2.0. u can use JDBC2.0 CachedRowSet.size() to retrieve the number of rows got by a ResultSet.

  • Number of columns in a table

    Hi,
    I am developing an application using jdbc. Is there any method which returns the number of columns in a table.
    Thanks
    Mallo

    actually, this exact code is posted in the docs that I gave the link to:
    ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
    ResultSetMetaData rsmd = rs.getMetaData();
    int numberOfColumns = rsmd.getColumnCount();Jamie

  • Can I know the name, type, total number of column in Record Group?

    I created a record group with query dynamically.
    And then populated it.
    I don't know the column' count, type, name befause I get the query from user at runtime.
    Can I know the name, type, total number of column in Record Group?

    Unfortunately, there is no way to query the record group (RG) to get the metadata you are looking for. RGs are best used as data sources to an LOV or List Item rather than as an Array to hold the resultset of a dynamic query. For this, I would recommend you use a Collection type of construct (PL/SQL Table of Records, VArray, etc).
    Craig...

  • Count the number of columns return in an user-input sql query

    I need to do something like this
    I let an user input a sql query and then execute it
    assuming the sql query is always correct, it will return a Resultset
    then a table will pop up to accomodate the number of columns the resultset will produce
    i'm stuck at the part on how to check how many columns of data will be return in the resultset

         ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
         ResultSetMetaData rsmd = rs.getMetaData();
         int numberOfColumns = rsmd.getColumnCount();

  • How to clone data with in Table with dynamic 'n' number of columns

    Hi All,
    I've a table with syntax,
    create table Temp (id number primary key, name varchar2(10), partner varchar2(10), info varchar2(20));
    And with data like
    insert itno temp values (sequence.nextval, 'test', 'p1', 'info for p1');
    insert into temp values (sequence.nextval, 'test', 'p2', 'info for p2');
    And now, i need to clone the data in TEMP table of name 'test' for new name 'test1' and here is my script,
    insert into Temp  select sequence.nextval id, 'test1' name, partner, info from TEMP where name='test1';
    this query executed successfully and able to insert records.
    The PROBLEM is,
    if some new columns added in TEMP table, need to update this query.
    How to clone the data with in the table for *'n' number of columns and*
    some columns with dynamic data and remaining columns as source data.
    Thanks & Regards
    PavanPinnu.
    Edited by: pavankumargupta on Apr 30, 2009 10:37 AM

    Hi,
    Thanks for the quick reply.
    My Scenario, is we have a Game Details table. When ever some Game get cloned, we need to add new records in to that Table for the new Game.
    As, the id will be primary key, this should populate from a Sequence (in our system, we used this) and Game Name will be new Game Name. And data for other columns should be same as Parent Game.
    when ever business needs changes, there will be some addition of new columns in Table.
    And with the existing query,
    insert into Temp (id, name, partner, info) select sequence.nextval id, 'test1' name, partner, info from TEMP where name='test'_
    will successfully add new rows but new added columns will have empty data.
    so, is there any way to do this, i mean, some columns with sequence values and other columns with existing values.
    One way, we can do is, get ResultSet MetaData (i'm using Java), and parse the columns. prepare a query in required format.
    I'm looking for alternative ways in query format in SQL.
    Thanks & Regards
    PavanPinnu.
    Edited by: pavankumargupta on Apr 30, 2009 11:05 AM
    Edited by: pavankumargupta on Apr 30, 2009 11:05 AM

  • Dynamic column fields of ResultSet

    Hi guys,
    I am working on a web-based system where user also specifies the column fields of ResultSet he/she wants to see. SQL query will display all the results for those selected column fields only.
    Suppose user selected Last Name and First Name.Then my ResultSet will display reports with Last Name and First Name column headings and first name and last name values only of the ResultSet.
    If the user specifies ID number, Address,City, State, Zip then ResultSet will display reports with these column headings and values only.
    I am using Oracle 8i to pull the values.Anyone got any idea how to implement it?
    Any help or suggestion would be highly appreciated.
    Thanks

    Ok Guys, I am attaching a small part of my code on the page below. This is the working code that I have written till now.
    NOw problems with this:
    (1) I can easily substitute "*" in SQl query with the column field variables. But first of all I need the columns to appear in order of priority. Like as I said earlier if last name, first name selected it should appear first then the address and so on.
    (2) The Column names that I have hardcoded, how to do away with that while still having column names on top like "First Name" and "Last Name"
    <jsp:useBean id="DataBean" scope="request" class="office.DataBean" />
    <jsp:useBean id="FormBean" scope="request" class="office.FormBean" />
    <%
    String result = "";
    DataBean.connect();
    FormBean.setRequest(request);
    String classify[] = request.getParameterValues("classify");
    int size2 = classify.length;
    String beta = "";
    String beta1 = "";
    if ((size2 == 1) && (classify[0].equals("all")))
    beta = "all";
    else if ((size2 == 1) && (classify[0] != "all"))
    beta = "wk_char30_4 = '" + classify[0]+ "'";
    else if ((classify[0].equals("all")) && (size2 != 1))
    beta = "all";
    else
    for(int p = 0; p < size2-1; p++)
    beta1 = beta1 + "'" + classify[p] + "'" + ",";
    beta1= beta1 + "'" + classify[size2-1] + "'";
    beta = " wk_char30_4 IN (" + beta1 + ")";
    %>
    <h3 align = center>Selected Employee Records between <%=begin%> to <%=end%> </h3>
    <%
    boolean filterbyclassify = beta.equalsIgnoreCase("all");
    String sql = "SELECT * FROM f_personnel, f_repair_center where" +
    (filterbyactive?" wk_active IN ('YES','NO') ":" wk_active = '" + active + "'") +
    (filterbysupervisor?"":" and wk_is_supervisor = '" + supervisor + "'") +
    (filterbyclassify?"":" and " + beta )+
    " ORDER BY wk_last_name, wk_first_name";
    DataBean.setSql(sql);
    int counter = 0;
    int temp = 0;
    %>
    <html>
    <title>
    Employee System
    </title>
    <body>
    <script type="text/javascript">
    function set(n,length)
    var thisBox;
    for (i=0; i < length; i++)
    thisBox = 'document.myForm.req' + i;
    eval(thisBox).checked = n;
    </script>
    <table border=2 cellpadding=4 align=center bordercolor=black>
    <tr align=center>
    <td ><h4>Select</h4></td>
    <td ><h4>Last Name</h4></td>
    <td ><h4>First Name</h4></td>
    <td ><h4>ID Code</h4></td>
    </tr>
    <% String lname="",fname="",code="";%>
    <form name="myForm" action= "test2.jsp" method = "post">
    <% while (DataBean.getNextRow())
    lname=DataBean.getString("wk_last_name") ;
    fname=DataBean.getString("wk_first_name") ;
    code=DataBean.getString("wk_id_code");
    %>
    <tr align=left bgcolor= <% counter++; if (counter % 2 ==1) out.print("#CC9999"); else out.print("#D3D3D3");%>>
    <td ><input type="checkbox" name="req<%=temp%>" value="<%=lname%>,<%=fname%>,<%=code%>"></td>
    <td ><font size="-1"><%=lname%></font></td>
    <td ><font size="-1"><%=fname%></font></td>
    <td ><font size="-1"><%=code%></font></td>
    <%temp++ ;%>
    </tr>
    <%
    }%>
    <input type = hidden name=temp value=<%=temp%>>
    <input type = hidden name=begin value=<%=begin%>>
    <input type = hidden name=end value=<%=end%>>
    <p>
    <input name=button onclick=set(1,<%=temp%>) type=button value="Select All">
    <input name=button onclick=set(0,<%=temp%>) type=button value=" Reset ">
    <input type =submit name="Save Selection" value = "Save Selection">
    </p>
    </form>
    </table>
    <% DataBean.disconnect(); %>
    </body>
    </html>

  • Printing with 1 additional column every time resultSet  is given

    I have a resultSet that will return an extra column everytime around. I want to my Printing loop(code below) to be able to print an extra column everytime the resultSet is brought back with new data. How can this be done?
    do{     
                   String column1 = rs.getString(1);
                   String column2 = rs.getString(2);
              System.out.println (column1 + column2);
    }while (rs.next());

    It's weird that the number of columns would grow each time you run it. It sounds like you have an oddly-arranged schema.
    Anyway, what you want is the java.sql.ResultSetMetaData. Read the API docs about it. It'll tell you how many columns there are, what types they are, etc., so you can then change what you read from the results. You'll probably end up with a new nested loop inside the existing one, rather than hardcoding as you have now.

  • Slow conversions of Number(x) columns with getLong()

    JDK 1.3
    WLS 5.1.0 / SP10
    Solaris 8
    Oracle Type 4 drivers - classes12.zip
    I have thirty one threads like this one - only one is running (one cpu machine).
    This is a getLong() on a Number(10) column. Will changing the column to Long
    help?
    Any ideas why this is slow/bottleneck?
    I just discovered some OutOfMemoryErrors and will be fixing that.
    "ExecuteThread-291" daemon prio=5 tid=0x6a3bb0 nid=0x132 waiting on monitor [0xd
    b080000..0xdb0819e0]
    at oracle.sql.NUMBER._isPositive(NUMBER.java:2882)
    at oracle.sql.NUMBER._fromLnxFmt(NUMBER.java:2953)
    at oracle.sql.LnxLibThin.lnxsni(LnxLibThin.java:871)
    at oracle.sql.NUMBER.toLong(NUMBER.java:323)
    at oracle.sql.NUMBER.longValue(NUMBER.java:1812)
    at oracle.jdbc.dbaccess.DBConversion.NumberBytesToLong(DBConversion.java:181
    7)
    at oracle.jdbc.driver.OracleStatement.getLongValue(OracleStatement.java:3200
    at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:3
    35)
    at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1432)
    Mike

    http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.jdbc&item=6829&utag=
    ever have one of those days where you end up talking to yourself?
    mike
    "Mike Reiche" <[email protected]> wrote:
    >
    a developer tells me the code below works with type 4 drivers, but type
    2 driver
    complains about hte Oracle.Type.Cursor. What
    type should that be? Will java.sql.Other work?
    CallableStatement cstmt = con.prepareCall(callString);
    cstmt.registerOutParameter(1, OracleTypes.INTEGER);
    cstmt.setLong(2, 24);
    cstmt.registerOutParameter(3, OracleTypes.CURSOR);
    cstmt.execute();
    rs=(ResultSet)cstmt.getObject(3);

  • How to find the number of columns in an internal table DYNAMICALLY ?

    Hi,
    How to find the number of columns in an internal table DYNAMICALLY ?
    Thanks and Regards,
    saleem.

    Hi,
    you can find the number of columns and their order using
    the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
       I_PROGRAM_NAME               = sy-repid
       I_INTERNAL_TABNAME           = 'ITAB'
       I_INCLNAME                   = sy-repid
      changing
        ct_fieldcat                  = IT_FIELDCAT
    EXCEPTIONS
       INCONSISTENT_INTERFACE       = 1
       PROGRAM_ERROR                = 2
       OTHERS                       = 3
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif
    now describe your fieldcat . and find no of columns.
    and their order also..
    regards
    vijay

  • Is their any limit on the number of column updates in a update statement!

    Hello All,
    Is their any limit on the number of columns to set in a single update statement.+
    am using oracle 11g .
    example :-
    UPDATE FMLY SET as_comp1 = v_as_comp1 , as_comp2 = v_as_comp2, as_comp3 = v_as_comp3, as_comp4 = v_as_comp4 , as_comp5 = v_as_comp5 ,      perslt18 = v_perslt18 , persot64  = v_persot64  , fam_size = v_fam_size , numchild = total_children , C_AGE1 = v_c_age1,  C_AGE2 = v_c_age2,  C_AGE3 = v_c_age3,  C_AGE4 = v_c_age4 WHERE FAMID = fmly_famid(i) ;
    and also is it good practice to issue single update or multiple updates ?
    example for the above update i can have multiple statements like .. does the performance matters if so which is good
    UPDATE FMLY SET as_comp1 = v_as_comp1 , as_comp2 = v_as_comp2, as_comp3 = v_as_comp3, as_comp4 = v_as_comp4 , as_comp5 = v_as_comp5
    WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET perslt18 = v_perslt18 , persot64 = v_persot64 , fam_size = v_fam_size
    WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET numchild = total_children WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET C_AGE1 = v_c_age1, C_AGE2 = v_c_age2, C_AGE3 = v_c_age3, C_AGE4 = v_c_age4 WHERE FAMID = fmly_famid(i) ;
    thanks/kumar
    Edited by: kumar73 on Sep 25, 2010 8:38 AM

    If you can do it in a single SQL statement then you should do that.
    Here's a mantra that I found to work out pretty good:
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:73891904732164

Maybe you are looking for

  • SPO based on Infocube activation issue

    Hi All, I am getting below error while activating the SPO based on Infocube. We are on BW 7.31 SP03. Please let me know if you face this issue... Error message - Call of the method CONSTRUCTOR of the class CX_RSLPO_OPERATION_FAILED failed; wrong type

  • ITunes 11 not switchable to Discrete Graphics

    Hello! I'm trying to switch iTunes to use the Discrete Graphics chip instead of the Integrated Graphics. That's especially interesting when running the visualizer @ full screen 2560x1600 res. Various other apps (Photoshop, Chrome...etc.) support swit

  • How to reset automatic payment (F110)

    Hello SAP Gurus, can anyone tell me how to reset automatic payment? or how to remove/delete the payment request? needed badly. thanks! Edited by: nanz ruiz on Apr 1, 2009 4:17 AM

  • Iphone 4 in recovery mode after restore

    After buying a new computer and attempting to sync my iPhone 4 to the media library on the new computer, it kept telling me I needed more space on the phone (wrong) so I attempted to restore the phone and erase the memory, so I could start fresh. How

  • Getting ORA-1260 TNS:

    Help, I need your help, I dwnld cpy of Oracle8i to Windows/NT loaded w/ Universal Installer tried to log on w/ LogonID: Scott Psswd:Tiger But got ORA-12560 TNS:protocol adapter error To see more information, send responses thks