Example usage for java.sql ResultSet close

List of usage examples for java.sql ResultSet close

Introduction

In this page you can find the example usage for java.sql ResultSet close.

Prototype

void close() throws SQLException;

Source Link

Document

Releases this ResultSet object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

Usage

From source file:JndiDataSource.java

public static void main(String args[]) throws Exception {
    String sp = "com.sun.jndi.fscontext.RefFSContextFactory";
    String file = "file:/e:/JNDI";
    String dataSourceName = "jdbc/myDatabase";

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, sp);
    env.put(Context.PROVIDER_URL, file);
    ctx = new InitialContext(env);

    bindDataSource(ctx, dataSourceName);

    DataSource ds = null;/*from w  ww.j ava2 s .  co  m*/
    ds = (DataSource) ctx.lookup(dataSourceName);

    Connection conn = ds.getConnection();

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT Name FROM Employees");

    while (rs.next())
        System.out.println(rs.getString("name"));

    ctx.close();
    rs.close();
    stmt.close();
    conn.close();

    ctx.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,null)");
    st.executeUpdate("insert into survey (id,name ) values (3,'Tom')");
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    // Move cursor to the last row
    rs.last();//from w ww.  ja  v  a  2  s  .  com
    // Get data at cursor
    String id = rs.getString("id");
    System.out.println(id);

    rs.close();
    st.close();
    conn.close();
}

From source file:TestThinDSApp.java

public static void main(String args[]) throws ClassNotFoundException, SQLException {

    // These settings are typically configured in JNDI
    // so they a implementation specific
    OracleDataSource ds = new OracleDataSource();
    ds.setDriverType("thin");
    ds.setServerName("dssw2k01");
    ds.setPortNumber(1521);//  w w  w.j ava2 s .c  o m
    ds.setDatabaseName("orcl"); // sid
    ds.setUser("scott");
    ds.setPassword("tiger");

    Connection conn = ds.getConnection();

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
            "select 'Hello Thin driver data source tester '||" + "initcap(USER)||'!' result from dual");
    if (rset.next())
        System.out.println(rset.getString(1));
    rset.close();
    stmt.close();
    conn.close();
}

From source file:TestSSL.java

public static void main(String[] argv) throws Exception {

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Properties prop = new Properties();
    prop.setProperty("user", "scott");
    prop.setProperty("password", "tiger");
    // THIS DOES NOT WORK YET
    prop.setProperty("oracle.net.ssl_cipher_suites",
            "(ssl_rsa_export_with_rc4_40_md5, ssl_rsa_export_with_des40_cbc_sha)");
    prop.setProperty("oracle.net.ssl_client_authentication", "false");
    prop.setProperty("oracle.net.ssl_version", "3.0");
    prop.setProperty("oracle.net.encryption_client", "REJECTED");
    prop.setProperty("oracle.net.crypto_checksum_client", "REJECTED");
    Connection conn = DriverManager.getConnection(
            "jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCPS)(HOST = dssw2k01)(PORT = 2484))) (CONNECT_DATA = (SERVICE_NAME = DSSW2K01)))",
            prop);/*from  w w  w  .ja v  a  2s  . com*/
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt
            .executeQuery("select 'Hello Thin driver SSL " + "tester '||USER||'!' result from dual");
    while (rset.next())
        System.out.println(rset.getString(1));
    rset.close();
    stmt.close();
    conn.close();
}

From source file:TestDataEncryptionIntegrity.java

public static void main(String[] argv) throws Exception {

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Properties prop = new Properties();
    prop.setProperty("user", "scott");
    prop.setProperty("password", "tiger");
    prop.setProperty("oracle.net.encryption_client", "REQUIRED");
    prop.setProperty("oracle.net.encryption_types_client", "( RC4_40 )");
    prop.setProperty("oracle.net.crypto_checksum_client", "REQUIRED");
    prop.setProperty("oracle.net.crypto_checksum_types_client", "( MD5 )");

    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", prop);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
            "select 'Hello Thin driver Encryption & Integrity " + "tester '||USER||'!' result from dual");
    while (rset.next())
        System.out.println(rset.getString(1));
    rset.close();
    stmt.close();// w  w w. j  a  v  a2 s.c o m
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,null)");
    st.executeUpdate("insert into survey (id,name ) values (3,'Tom')");

    ResultSet rs = st.executeQuery("SELECT id,name FROM survey");

    rs.moveToInsertRow();/*from   w  ww .ja v a  2s.  c o m*/

    rs.updateString("id", "66");
    rs.updateString("name", "H F");

    // Insert the row
    rs.insertRow();

    rs.close();
    st.close();
    conn.close();
}

From source file:TestDSLookUp.java

public static void main(String[] args) throws SQLException, NamingException {

    Context ctx = null;//from w ww.jav a2 s  .co  m
    try {
        Properties prop = new Properties();
        prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
        ctx = new InitialContext(prop);
    } catch (NamingException ne) {
        System.err.println(ne.getMessage());
    }

    DataSource ds = (DataSource) ctx.lookup("joe");
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
            "select 'Hello Thin driver data source tester '||" + "initcap(USER)||'!' result from dual");
    if (rset.next())
        System.out.println(rset.getString(1));
    rset.close();
    stmt.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement stmt = conn.createStatement();

    stmt.executeUpdate("create table survey (id int, name CHAR(5) );");

    stmt.executeUpdate("INSERT INTO survey(id, name)VALUES(111, '123456789')");

    ResultSet rs = stmt.executeQuery("SELECT * FROM survey");
    outputResultSet(rs);/*from w  w w  .j a v a  2 s  . c o m*/

    stmt.executeUpdate("delete from survey");

    rs = stmt.executeQuery("SELECT * FROM survey");
    outputResultSet(rs);

    rs.close();
    stmt.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class.forName("org.sqlite.JDBC");

    Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");

    Statement stat = conn.createStatement();
    stat.executeUpdate("drop table if exists people;");
    stat.executeUpdate("create table people (name, occupation);");
    PreparedStatement prep = conn.prepareStatement("insert into people values (?, ?);");

    prep.setString(1, "G");
    prep.setString(2, "politics");
    prep.addBatch();// www . j  av  a2 s . c om
    prep.setString(1, "Turing");
    prep.setString(2, "computers");
    prep.addBatch();
    prep.setString(1, "W");
    prep.setString(2, "Tester");
    prep.addBatch();

    conn.setAutoCommit(false);
    prep.executeBatch();
    conn.setAutoCommit(true);

    ResultSet rs = stat.executeQuery("select * from people;");
    while (rs.next()) {
        System.out.println("name = " + rs.getString("name"));
        System.out.println("job = " + rs.getString("occupation"));
    }
    rs.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();
    Statement st = conn.createStatement();
    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");

    st = conn.createStatement();/*from  w  ww.  j av  a 2s  .  co  m*/
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    ResultSetMetaData rsMetaData = rs.getMetaData();

    int numberOfColumns = rsMetaData.getColumnCount();
    System.out.println("resultSet MetaData column Count=" + numberOfColumns);

    rs.close();
    st.close();
    conn.close();
}