Home Discussion Discuss: Java get number of rows in resultset

  • not really...Some Guy June 18, 2013 at 10:13 PM

    This is not very general and it depends on your id column being perfect. If you were to delete row 3 in the table you suggest the program would still return 4. Thus it does not return the number of rows, by the Id to the last given row.

  • More Efficient Result Set Row CountJeff August 14, 2013 at 9:10 PM

    A way I usually use to get the number of rows in a result is to jump to the last row in the result set and get its index. This just requires a scroll insensitive result set. I am not sure of the complexity of ResultSet.last() over a loop but i am confident its quicker. ie. // Creating prepared statement prepared = conn.prepareStatement("Some SQL Statement WHERE thing =?", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); prepared.setInt(1, uniqueId); // Executing Query ResultSet result = prepared.executeQuery(); // Getting row count result.last(); int rowCount = result.getRow(); retult.beforeFirst();

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
General

Java get number of rows in resultset
Java get number of rows in resultset  ...() get the row number of the last row and also shows you the number of rows... to retrieve the number of rows from the database table. As you know that the data 

Servlets

Getting Number of Rows
the ResultSet object, by the help of this object we can get the number of rows we have... on the browser. To get the number of rows from the database table there is a need... Getting Number of Rows      

Java-Tutorials

Get rows count and get columns names
COUNT ROWS AND GET COLUMN NAMES OF A TABLE   In this program , we count the number of data rows stored in a table.  getcolname.java  ...++;                 }       System.out.println("Number of Rows present in table : "+count 

JDBC

Rows Count Example Using JDBC ResultSet
Rows Count Example Using  JDBC ResultSet: In this tutorial you can count the number of rows in the database table using ResultSet. Through this example... object using next() and find the number of rows as: rs.next 

Java-Tutorials

Getting the Number of Rows and Columns in JTable
will learn how to get the number of rows and columns in JTable.  This program... get the number of rows and column to its name (Column name) in the command line... Getting the Number of Rows and Columns in JTable  

JDBC

Get Column Count using ResultSet in SQL
Get Column Count using ResultSet in SQL    This example counts the number of columns in a table... connection is established and how to get required data, like the number 

Java Beginners

Scrollable ResultSet - Java Beginners
get the number of record for the Query. Your Answers use the scrollable result set, first move the pointer from first record to last record and get... to get the count of records. in a select operation like sqlstmt="SELECT * FROM 

JDBC-Tutorials

ResultSet In Java
ResultSet In Java In this section we will learn about the ResultSet in Java... that are mostly used in to get the value. ResultSet contains the data of a table after... example which will demonstrate you about how to use the ResultSet in Java 

JSP Servlet Questions

Getting ResultSet size - JSP-Servlet
the driver. It has absolutely no effect on the number of rows in a ResultSet. The driver... rows in the result from the database to the Java client at once, i.e. no buffering...Getting ResultSet size  Hello friends, what 

Java-Tutorials

JDBC: Rows Count Example
JDBC: Rows Count Example In this section, You will learn how to count number of rows in a table using JDBC API. Counting number of rows - To count the number of rows of a table we use COUNT(*). It will returns the number of rows 

WebSevices Questions

resultset metadta
resultset metadta  import java.sql.Connection; import... Employee Details Using resultset metadata: "); Connection con = null...(); ResultSet rs = st.executeQuery("SELECT * FROM employee 

JDBC

Count Rows from a Database Table
to know number of rows in a table then we can get it very easily by using the simple... Count number of rows in a specific table! Enter table name: student... Count Rows from a Database Table    

SQL Question

Write a query to find the total number of rows in a table
Write a query to find the total number of rows in a table  Write a query to find the total number of rows in a table?   Hi, Here is the answer, we can find the total number of rows in a table using following query 

MySQL

PHP SQL Number of Rows
PHP SQL Number of Rows      .... To understand how to count the number of rows in a table, we have created a sql_num_rows.php...;). The number of rows are returned by the mysql_num_rows() method.     

JSP Servlet Questions

Resultset - JSP-Servlet
, and because it returns false when there are no more rows in the ResultSet object...Resultset  I am writing while(rs.next){} but if resultset is null then it cannot enter in while block. I want,if resultset is null 

PHP

Php Sql Number of Rows
Php Sql Number of Rows  This example illustrates how to count the rows... of rows of the table. To find the number of the rows we use the mysql_num_rows..._rows($res);     print("$number_of_rows rows  

JDBC Questions

ResultSet
ResultSet   What is a ResultSet 

Java Interview Questions

ResultSet
ResultSet  What is a ResultSet 

Java Beginners

converting Json data into rows of DTO in java
' number of ways to convert this JSON data into rows of DTO. I have used all...converting Json data into rows of DTO in java  I am using jqxgrid, and I am able to access the json data in JAVA controller. But now my requirement 

JDBC Questions

ResultSet
ResultSet  I want to retrieve data of unknown datatype from database.how to do it using resultset or Resultsetmetadata.Can you please tell me what... = con.createStatement(); ResultSet rs = st.executeQuery 

PHP

Php Sql num rows
Php Sql num rows This example illustrates how to find number of rows... and find the number of rows of the table by mysql_num_rows methods. The output...);   $num_rows = mysql_num_rows($result);    

PHP Questions

How can we find the number of rows in a result set using PHP?
How can we find the number of rows in a result set using PHP?   How can we find the number of rows in a result set using PHP 

Java Beginners

ResultSet object initialization - Java Beginners
ResultSet object initialization  How to initialize resultset object  Hi friend, public interface ResultSet A ResultSet object maintains a cursor pointing to its current row of data. A default ResultSet object 

Java Code Examples

Show multiple identical rows into JTable from database
, then all the data associated with that name will get displayed into JTable rows...Show multiple identical rows into JTable from database In this tutorial, you will learn how to display the multiple rows from database to JTable. Here 

JDBC Questions

Executing anonymous pl/sql block and get resultset in Java
Executing anonymous pl/sql block and get resultset in Java  Hello All, I would like to execute the anonymous pl sql block and need to get the resultset object. I got the code which can be done by using cursors inside the pl sql 

JDBC

JDBC ResultSet Delete Row Example
JDBC ResultSet Delete Row Example: Learn how to delete row using ResultSet. We are also used ResultSet object with update capability for delete rows from...() method on the created statement object to return ResultSet object on the table 

JavaScript Questions

Grid rows delete issue
on onchange of dropdown then because of rows indexing issue,they can't get middle row...Grid rows delete issue  I have a grid having rows with Remove button to remove rows,But we also havae an facility to remove those rows on onchange 

JDBC

JDBC Batch SQL Update Statement Example With Return Number of Effected Rows
JDBC Batch SQL Update Statement Example With Return Number of Effected Rows: In this example, we are discuss about update statement with return number of effected rows. The executebatch() method are use to execute the batch 

JSP Servlet Questions

How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?
;   The given code count the number of rows in a database table. <..._Register"; ResultSet rs = st.executeQuery(query); if(rs.next()) { rows... display page for a resultSet() in jsp?  this is count record code 

MySQL

Php Sql num rows
; This tutorial illustrates how to find number of rows of the table... to find the number of rows in the table. We created a connection from database...("SELECT * FROM tableName"). The number of rows are returned by the mysql 

DMCA.com