P
Pulse Beacon

What will happen if ResultSet () is not present in JDBC

Author

David Jones

Published Apr 21, 2026

If you do not specify any ResultSet type, you will automatically get one that is TYPE_FORWARD_ONLY. The cursor can only move forward in the result set. The cursor can scroll forward and backward, and the result set is not sensitive to changes made by others to the database that occur after the result set was created.

What happens if ResultSet is not closed?

In a pooled database connection, it is returned to the pool and could close only after expiring its life time. If it happens on a single database by multiple applications, the data updation is not perfect and may violate ACID properties rule for data presuming. …

What is the role of Statement object and ResultSet in JDBC?

createStatement() method on Connection object will return Statement object. JDBC ResultSet: … ResultSet also an interface and is used to retrieve SQL select query results. A ResultSet object maintains a cursor pointing to its current row of data.

What is the purpose of ResultSet in Java?

A ResultSet is a Java object that contains the results of executing an SQL query. In other words, it contains the rows that satisfy the conditions of the query. The data stored in a ResultSet object is retrieved through a set of get methods that allows access to the various columns of the current row.

What happens if you close the ResultSet object?

What happens if you call the method close ( ) on a ResultSet object ? A. the method close ( ) does not exist for a Result Set . … The row you are positioned on is deleted from the ResultSet , but not from the database .

Why is ResultSet closed?

A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results. The number, types and properties of a ResultSet object’s columns are provided by the ResultSetMetaData object returned by the ResultSet.

What happens if connection is not closed in JDBC?

2 Answers. If we don’t close the connection, it will lead to connection memory leakage. Until application server/web server is shut down, connection will remain active, even if the user logs out.

What happens if you call deleteRow () on a ResultSet object?

What happens if you call deleteRow() on a ResultSet object? … The row you are positioned on is deleted from the ResultSet, but not from the database.

What are the type of ResultSet in JDBC?

Based on the concurrency there are two types of ResultSet object. CONCUR_READ_ONLY: The ResultSet is read-only, this is the default concurrency type. CONCUR_UPDATABLE: We can use the ResultSet update method to update the rows data.

What is the right way to get the numbers data using ResultSet object in JDBC?

Getter methods are used to get the values of the table in ResultSet. For that, we need to pass either column Index value or Column Name. The following are the getter methods in ResultSet: int getInt(int ColumnIndex): It is used to get the value of the specified column Index as an int data type.

Article first time published on

What is the purpose of Statement object in JDBC?

A Statement object is used to execute a simple SQL statement with no parameters. A PreparedStatement object is used to execute a pre-compiled SQL statement with or without IN parameters. A CallableStatement object is used to execute a call to a database stored procedure.

Which of the following is not a valid statement in JDBC?

Explanation. QueryStatement is not a valid type of statement in JDBC.

What are the exceptions in JDBC?

Exception handling allows you to handle exceptional conditions such as program-defined errors in a controlled fashion. When an exception condition occurs, an exception is thrown. The term thrown means that current program execution stops, and the control is redirected to the nearest applicable catch clause.

What should be closed in any of JDBC Statement?

Note that JDBC resources should always be closed, so, its better to put that to the ‘finally’ block.

Does closing connection close ResultSet?

Closing connection object closes the statement and resultset objects but what actually happens is that the statement and resultset object are still open (isClosed() returns false).

Can we use ResultSet after closing connection?

Once the connection is closed you can no longer use any of the resources (statements, prepared statements, result sets). So you need to do all of your processing while the resources are open.

Is it necessary to close JDBC connection?

It is important to close a JDBC Connection once you are done with it. A database connection takes up an amount of resources, both inside your own application, but especially on the database server.

Is it necessary to close connection?

2 Answers. No, they wouldn’t be closed. If getConnection() creates a new Connection, then the only thing that will happen at the end of the method is that the Connection could be garbage collected.

What happens if we don't close the DB connection each time will garbage collector will take care of closing DB connections?

If you don’t close() these connections, the pool wont know you are finished with them and wont be able to reuse them for other requests, and the connection pool will be exhausted.

Should I close ResultSet?

You should explicitly close Statements , ResultSets , and Connections when you no longer need them, unless you declare them in a try -with-resources statement (available in JDK 7 and after). Connections to Derby are resources external to an application, and the garbage collector will not close them automatically.

How do I know if my ResultSet is closed?

The ResultSet object contains a cursor/pointer which points to the current row. Initially this cursor is positioned before first row (default position). The isClosed() method of the ResultSet interface is used to determine whether the current ResultSet object is closed.

What is not the type of ResultSet in JDBC?

If you do not specify any ResultSet type, you will automatically get one that is TYPE_FORWARD_ONLY. The cursor can only move forward in the result set. The cursor can scroll forward and backward, and the result set is not sensitive to changes made by others to the database that occur after the result set was created.

Which of the following is not a JDBC connection isolation levels?

Explanation: TRANSACTION_NONREPEATABLE_READ is not a JDBC connection isolation level.

Which of the following is correct about ResultSet class of JDBC?

Explanation. Statement encapsulates an SQL statement which is passed to the database to be parsed, compiled, planned and executed. Q 10 – Which of the following is correct about ResultSet class of JDBC? A – ResultSet holds data retrieved from a database after you execute an SQL query using Statement objects.

How many transaction isolation levels provide the JDBC through the connection interface?

JDBC provides support 5 transaction isolation levels through Connection interface.

Is the return type of next () method in ResultSet?

next() , it shifts the cursor to the next row of the result set from the database and returns true if there is any row, otherwise false .

Which of the following interface provides the commit () and rollback () methods?

The Connection interface is a factory of Statement, PreparedStatement, and DatabaseMetaData i.e. object of Connection can be used to get the object of Statement and DatabaseMetaData. The Connection interface provide many methods for transaction management like commit(), rollback() etc.

How you will change the data using ResultSet?

The method ResultSet. updateFloat updates the specified column (in this example, PRICE with the specified float value in the row where the cursor is positioned. ResultSet contains various updater methods that enable you to update column values of various data types.

What is RS next () in Java?

The next() method of the ResultSet interface moves the pointer of the current (ResultSet) object to the next row, from the current position. Statement stmt = con. createStatement(); ResultSet rs = stmt. … And on calling the next() method for the second time the result set cursor will be moved to the 2nd row.

What do we need to do if we want to go through the ResultSet object in forward and backward direction?

You can traverse through the contents of a ResultSet object in forward direction using the next() method and, you can traverse its contents in reverse direction using forward() method.

What are the functions of the JDBC connection interface?

Constructs an object that implements the NClob interface. Constructs an object that implements the SQLXML interface. Creates a Statement object for sending SQL statements to the database. Creates a Statement object that will generate ResultSet objects with the given type and concurrency.