reading total number of row with preparedstatement

Posted on 2006-04-26
Last Modified: 2010-04-17
Expert Exchange

Is there a way to read the total number of rows from a select satement using prepared statement, instead of having to loop throght the data and count as you go?
 rs1 = getIP.getResultSet();
 while (

but instead

int total =  command

Question by:tfbsr
    LVL 3

    Expert Comment

    You can try:
    Select Count(myTable.*) as Total
    From myTable

    That should return 1 row with a value and a column header 'Total'

    Good Luck!!!
    LVL 2

    Expert Comment

    What language are you using?  Most have something like rs1.RecordCount as a function that can be referenced once the rs1 has been populated.

    Author Comment

    Using Java
    LVL 2

    Expert Comment

    Sorry - don't know much about Java.  pitster's initial response will work for any query language so if you can't find another way it should get you there.

    Accepted Solution


    I suggest you set the result set to last and then you get the row number, this should give you the number of rows that was selected with your statement.

     rs1 = getIP.getResultSet();
     int rows = rs1.getRow()

    //if  you need to go to the first again

    Hope this helps.



    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now