Share on Google+Share on Google+

Find Default ResultSet Type Example

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.


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 {
        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");
        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


Posted on: October 23, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.


Advertisement null