ResultSet close Example

ResultSet class close example. This example shows you how to use close method.


ResultSet class close example. void close() throws SQLException Releases this ResultSet object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

Here is the code
/*
 * @ # Close.java
 * A class repersenting use to close method 
 * of ResultSet in java.sql package
 * version 01 July 2008
 * author Rose India 
 */

import java.sql.*;

public class Close {

  public static void main(String[] argsthrows 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);

      while (rs.next()) {
        System.out.println(rs.getString(1" " + rs.getString(2));
      }

      rs.close();
      st.close();
      con.close();
    catch (Exception e) {
      System.out.println("SQL statement is not executed!");
      System.out.println(e.toString());
    }
  }
}

Output
100 Mahendra
102 Ravi
103 komal
109 Ravi1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US