get Result Set with read only cursor - Java java.sql

Java examples for java.sql:ResultSet

Description

get Result Set with read only cursor

Demo Code


//package com.java2s;
import java.sql.*;

public class Main {
    public static ResultSet getResultSet(Connection con, String sql) {
        try {/*from   w  w  w  .  j  a va  2  s  . co  m*/
            Statement st = con.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery(sql);
            return rs;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void executeQuery(Connection con, String sql) {
        Statement st;

        try {
            st = con.createStatement();
            st.executeUpdate(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials