Home Tutorial Java Jdbc Jdbcresultset Find Default ResultSet Type Example

 
 

Find Default ResultSet Type Example
Posted on: October 23, 2010 at 12:00 AM
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

Related Tags for Find Default ResultSet Type Example:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.