ResultSet first Example
ResultSet Interface first example. This example shows you how to use first method.
ResultSet Interface first example. boolean first() throws SQLException Moves the cursor to the first row in this ResultSet object.
Here is the code
/*
* @ # First.java
* A class repersenting use to first method
* of ResultSet in java.sql package
* version 01 July 2008
* author Rose India
*/
import java.sql.*;
public class First {
public static void main(String[] args) throws Exception {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.59:3306/";
String db = "Student";
Class.forName(driver);
con = DriverManager.getConnection(url + db, "root", "root");
try {
String sql = "Select * from stu_info";
st = con.createStatement();
rs = st.executeQuery(sql);
System.out.println("Moves the cursor to the first row : "
+ rs.first());
System.out.println(rs.getString(1) + " " + rs.getString(2));
rs.close();
st.close();
con.close();
} catch (Exception e) {
System.out.println(e.toString());
}
}
} |
Output
Moves the cursor to the first row : true
100 Mahendra |
|