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:PooledConnectionExample.java

private static void closeAll(ResultSet resultSet, Statement statement, Connection connection) {
    if (resultSet != null) {
        try {/*from  w  w  w. j  a  v a2s .c om*/
            resultSet.close();
        } catch (SQLException e) {
        } // nothing we can do
    }
    if (statement != null) {
        try {
            statement.close();
        } catch (SQLException e) {
        } // nothing we can do
    }
    if (connection != null) {
        try {
            connection.close();
        } catch (SQLException e) {
        } // nothing we can do
    }
}

From source file:com.plexobject.testplayer.dao.jdbc.JdbcUtil.java

static void attemptClose(ResultSet o) {
    try {//  w  w w .  j a  va 2  s .com
        if (o != null)
            o.close();
    } catch (Exception e) {
        log.error("Failed to close " + o, e);
    }
}

From source file:org.fornax.cartridges.sculptor.framework.util.db.DbUnitConnection.java

private static void close(Connection con, Statement stmt, ResultSet rs) {
    if (rs != null) {
        try {//from   ww  w.  ja  v a2 s. c  o m
            rs.close();
        } catch (SQLException ignore) {
        }
    }
    if (stmt != null) {
        try {
            stmt.close();
        } catch (SQLException ignore) {
        }
    }
    if (con != null) {
        try {
            con.close();
        } catch (SQLException ignore) {
        }
    }
}

From source file:$.DeviceTypeUtils.java

public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                log.warn("Error occurred while closing result set", e);
            }// w w w.ja v a 2  s .c  o m
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                log.warn("Error occurred while closing prepared statement", e);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                log.warn("Error occurred while closing database connection", e);
            }
        }
    }

From source file:SerializeJavaObjects_MySQL.java

public static long writeJavaObject(Connection conn, Object object) throws Exception {
    String className = object.getClass().getName();
    PreparedStatement pstmt = conn.prepareStatement(WRITE_OBJECT_SQL);

    // set input parameters
    pstmt.setString(1, className);/*  w ww  .ja  v  a  2  s  . c  om*/
    pstmt.setObject(2, object);
    pstmt.executeUpdate();

    // get the generated key for the id
    ResultSet rs = pstmt.getGeneratedKeys();
    int id = -1;
    if (rs.next()) {
        id = rs.getInt(1);
    }

    rs.close();
    pstmt.close();
    System.out.println("writeJavaObject: done serializing: " + className);
    return id;
}

From source file:Main.java

public static Object readJavaObject(Connection conn, long id) throws Exception {
    PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL);
    pstmt.setLong(1, id);//from  w  w  w  . j  a va 2  s  .co m
    ResultSet rs = pstmt.executeQuery();
    rs.next();
    Object object = rs.getObject(1);
    String className = object.getClass().getName();
    rs.close();
    pstmt.close();
    return object;
}

From source file:com.forsrc.utils.DbUtils.java

/**
 * Close.//  w  ww  .  ja  va 2  s  . com
 *
 * @param stmt the stmt
 * @param rs   the rs
 */
public static void close(Statement stmt, ResultSet rs) {

    try {
        if (null != rs) {
            rs.close();
        }
    } catch (SQLException e) {
        //LogUtils.LOGGER.error(e.getMessage(), e);
    }

    try {
        if (null != stmt) {
            stmt.close();
        }
    } catch (SQLException e) {
        //LogUtils.LOGGER.error(e.getMessage(), e);
    }

}

From source file:at.molindo.dbcopy.util.Utils.java

public static void close(ResultSet rs) {
    if (rs != null) {
        try {//from ww  w. j  a v a 2  s  .c om
            rs.close();
        } catch (SQLException e) {
            log.warn("failed to close resultset");
        }
    }
}

From source file:cn.vlabs.umt.common.datasource.DatabaseUtil.java

/**
 * ?????//from   w w  w. j  a  v a2 s. c  o m
 * @param rs ?
 */
public static void closeResultSet(ResultSet rs) {
    if (rs != null) {
        try {
            rs.close();
        } catch (SQLException e) {
            log.error(rs, e);
        }
    }
}

From source file:com.afforess.nsdump.Test.java

public static void testNationDump() throws IOException, SQLException {
    NationsDump dump = new NationsDump();
    dump.parse();//w w w  . ja v  a  2 s.  co m

    Connection conn = dump.getDatabaseConnection();
    PreparedStatement statement = conn.prepareStatement("SELECT (name) FROM nations");
    ResultSet result = statement.executeQuery();
    int total = 0;
    while (result.next()) {
        total++;
    }
    result.close();

    System.out.println("Total nations: " + total);

    statement = conn.prepareStatement("SELECT * FROM nations WHERE name = 'sakhovelo'");
    result = statement.executeQuery();
    result.next();
    for (int i = 1; i <= 10; i++) {
        if (i == 4) {
            Clob clob = result.getClob(i);
            String motto = clob.getSubString(1, (int) clob.length());
            String mottoEscaped = StringEscapeUtils.unescapeHtml(motto);
            System.out.println("Raw: " + motto + " Escaped: " + mottoEscaped);
        } else {
            System.out.println(result.getString(i));
        }
    }

    File db = new File("./ns-db.h2.db");
    db.delete();
}