answersLogoWhite

0

What is Result set in java?

Updated: 8/10/2023
User Avatar

Mhamid564

Lvl 1
12y ago

Best Answer

A table of data representing a database result set, which is usually generated by executing a statement that queries the database.

A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.

A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options. Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2"); // rs will be scrollable, will not show changes made by others, // and will be updatable In simple words, result set can store the result of the database query(SQL query).

Visit here for more: docs.oracle.com/javase/1.4.2/docs/api/java/sql/ResultSet.html

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

java.sql.ResultSet is a java object that is used for database connectivity to hold the data returned by a select query.

When we run a select query it returns us the data in a table format with each row representing one logical group of data with a number of columns.

The result set would contain this table of data and each row can be accessed one by one. we can use the resultset.get() methods to get the data from it.

Example:

ResultSet rs = prepStmt.executeQuery(); //Assumption - prepStmt is a valid preparedstatement with a valid query

while(rs.next()){

System.out.println("Name: " + rs.getString(1));

System.out.println("Age: " + rs.getInt(2));

}

the rs.getString() method would return us a String data type and similarly the rs.getInt() would return us an integer data type

the numbers 1 & 2 represent the column position in the result set where our data is present.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

To get the results of a database query, which you can then process. Please note that an SQL SELECT command will often produce a result that consists of many rows (records) of data.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is Result set in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Define set in java?

A Java set is a collection of things that do not contain duplicate elements. Duplicates are prohibited from Java sets.


How do you set the constant textarea in java?

we can set the value of constant text area in Java in swing by creating a object of Jframe


Why does java does not run on Linux?

the short answer is that it does. assuming you have java installed and your path set, it's as easy as javac javafilename.java java javafilename or if you have it as a jar file java -jar jarfilename.jar


How do you set classpath for java?

Classpath for Java can only be set depending on what system is being used. The environment also has to be specified in order for Classpath to work at its best.


Why it is required to set path and classpath?

to compile and run java program you need to set path and classpath path refers to binary used to compile and run java program i.e. "javac" for compilation and "java" for execution


Which operator works like sizeof operator in Java?

Java does not have the sizeOf() operator or any operator that gives an equivalent result.


How do you set java environment variables?

You need to set The CLASSPATH variable which is an argument set on the command-line that tells the Java Virtual Machine where to look for user-defined classes and packages in Java programs. Syntax is java -classpath "path to the packages". Set the PATH variable if you want to be able to conveniently run the Java 2 SDK executables (javac.exe, java.exe, javadoc.exe, etc.) from any directory without having to type the full path of the command. To set the PATH permanently, add the full path of the j2sdk1.4.2_version\bin directory to the PATH variable. -sravyaa


When did Sun Microsystems split and become JAVA?

Sun Microsystems did not "split" to "become" Java. Sun is a company, which invented and set out the specifications for the Java programming language in 1995.


Difference between equals equals and equal in java?

"==" in java is the binary operator which compares two values and gives a boolean result While "=" in java is a assignment operator which assigns a value to a variable.


Who discovered java and when?

java was discovered by James gosling and Co. in 1991 at sun micro systems..they renamed oak to java..initially java used in programming for set top boxes (for movie on demand..)


How do you set core java class path?

in Windows : specify environment variable as classpath orset classpath="list of directories" e.g. set classpath="C:\java\lib"in Linux export CLASSPATH="your classpath" e.g. export CLASSPATH="/home/java/lib"


Why do you keep getting java updates?

By default Java is set to automatically check for updates. Disabling this depends on your platform. Windows users can disable it via the Java options in the control panel.