Home Tutorial Java Jdbc Jdbcresultset Find Default ResultSet Type Example

 
 

Share on Google+Share on Google+
Find Default ResultSet Type Example
Posted on: October 23, 2010 at 12:00 AM
Advertisement
We are discuss about to find out Default ResultSet type.

Find Default ResultSet Type Example:

We are discuss about to find out Default ResultSet type. There are many operations depends on the ResultSet support Type so you can find out the default ResultSet type using this example. We are using MySql database server for this example and get the meta data of this database using DatabaseMataData object as:

DatabaseMetaData meta = connection.getMetaData();

Using this DatabaseMetaData object you can find the result set support type.

Example:

package ResultSet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DatabaseMetaData;

public class DefaultResultSetType {

  public static void main(String[] args) {
    Connection connection = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "roseindia_jdbc_tutorials";
      String driverName = "com.mysql.jdbc.Driver";
      String userName = "root";
      String password = "root";
      
      try {
        Class.forName(driverName).newInstance();
        connection = DriverManager.getConnection(url+dbName, userName, password);

        Statement stmt = connection.createStatement();
        DatabaseMetaData meta = connection.getMetaData();
           
          ResultSet res = stmt.executeQuery("SELECT * FROM user");
          
          if (meta.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY)) {
              System.out.println("Default ResultSet Type Name : TYPE_FORWARD_ONLY");
          }
          if (meta.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)) {
             System.out.println("Default ResultSet Type Name : TYPE_SCROLL_INSENSITIVE");
          }
          if (meta.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)) {
             System.out.println("Default ResultSet Type Name : TYPE_SCROLL_SENSITIVE");
          }  
          
           res.close();
         stmt.close();
         connection.close();
        catch (Exception e) {
          System.err.println("Exception: "+ e.getMessage());
        }   
    
}
}

Now we will run this example using eclipse IDE and see the message on the eclipse console that display the default ResultSet type.

Program output:

Download source code

Advertisement

Related Tags for Find Default ResultSet Type Example:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com