JDBC ResultSet Interface
Overview
In this post, we will learn about JDBC ResultSet Interface in JDBC API. A Result Set represents a table of data, which is usually generated by executing an SQL statement that selects the data from the database. For example, SQL SELECT query.
Import ResultSet
We can import the ResultSet in the Java application code from the java.sql package.
import java.sql.ResultSet;
Code Example
The following code retrieves the rows from the dept database table.
String sqlQuery = “SELECT * FROM dept”;
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sqlQuery);
while (rs.next()) {
int deptno = rs.getInt(1);
String dname= rs.getString(2);
String loc = rs.getString(3);
System.out.println(String.format(“%-20s”, deptno)
+ String.format(“%-20s”, dname)
+ String.format(“%-20s”, loc));
}
—
Java Tutorials
Java Tutorial on this website:
https://www.testingdocs.com/java-tutorial/
For more information on Java, visit the official website :
More information about Oracle Database: