Wednesday, 1 October 2014

Check ResultSet Holdability

java.sql.DatabaseMetaData provides 'supportsResultSetHoldability' method which returns true if this database supports the given result set holdability, else false.

/* Step 1: Import sql package */
import java.sql.*;

public class SampleApp {
    
    /* Update username, password and driver details here */
    static Connection getConnection() throws ClassNotFoundException, SQLException{
         /* Step 2: Load Driver */
        System.out.println("Loading/Registering driver");  
       
        Class.forName("com.mysql.jdbc.Driver");
         
        /* Step 3: Open connection to database */
        System.out.println("Connecting to database");
        String url = "jdbc:mysql://localhost/world";
        String userName = "root";
        String pasword = "tiger";
        return DriverManager.getConnection(url, userName, pasword);
    }
    
    public static void main(String args[]) throws SQLException, ClassNotFoundException{      
        Connection conn = getConnection();
        DatabaseMetaData dm = conn.getMetaData();
        
        System.out.println(dm.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT));
        System.out.println(dm.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT));
        conn.close();
    }
}


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment