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:de.erdesignerng.dialect.msaccess.MSAccessFileFormat.java

private static int getTableCount(Connection aConnection, String aTableName) throws SQLException {

    String theColumnName = "theCount";
    short theResult = 0;
    String theSQL = "SELECT Count(MSysObjects.Id) AS " + theColumnName + " " + "FROM MSysObjects "
            + "WHERE (MSysObjects.Name LIKE ?);";

    PreparedStatement theStatement = aConnection.prepareStatement(theSQL);
    theStatement.setString(1, aTableName);

    ResultSet theIdentificationResult = theStatement.executeQuery();

    if (theIdentificationResult != null) {
        if (theIdentificationResult.next()) {
            theResult = theIdentificationResult.getShort(theColumnName);
        }//w w w. j av a 2 s  .c o  m

        theIdentificationResult.close();
    }

    return theResult;

}

From source file:gridool.util.jdbc.JDBCUtils.java

/**
 * Close a <code>ResultSet</code>, avoid closing if null.
 *///  w w  w .  ja  va2  s . com
public static void close(ResultSet rs) throws SQLException {
    if (rs != null) {
        rs.close();
    }
}

From source file:com.wso2telco.core.dbutils.DbUtils.java

/**
 * Close result set.// w w w  .ja  va  2  s .  c om
 *
 * @param resultSet
 *            the result set
 */
private static void closeResultSet(ResultSet resultSet) {
    if (resultSet != null) {
        try {
            resultSet.close();
        } catch (SQLException e) {
            log.warn("Database error. Could not close ResultSet  - " + e.getMessage(), e);
        }
    }

}

From source file:com.hangum.tadpole.summary.report.DailySummaryReportJOB.java

/**
 * ? quote sql? ? ./*from ww  w. j av  a2 s. c  o m*/
 * 
 * @param userDB
 * @param strDML
 * @param args
 */
public static String executSQL(UserDBDAO userDB, String strTitle, String strDML) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("execute query " + strDML);

    java.sql.Connection javaConn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        SqlMapClient client = TadpoleSQLManager.getInstance(userDB);
        javaConn = client.getDataSource().getConnection();
        stmt = javaConn.createStatement();
        rs = stmt.executeQuery(strDML);

        return DailySummaryReport.makeResultSetTOHTML(strTitle, rs, 100);
    } finally {
        try {
            if (rs != null)
                rs.close();
        } catch (Exception e) {
        }
        try {
            if (stmt != null)
                stmt.close();
        } catch (Exception e) {
        }
        try {
            if (javaConn != null)
                javaConn.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.concursive.connect.web.modules.wiki.utils.WikiUtils.java

public static HashMap<String, ImageInfo> buildImageInfo(Connection db, int projectId) throws SQLException {
    HashMap<String, ImageInfo> images = new HashMap<String, ImageInfo>();
    // Full size image
    PreparedStatement pst = db/*from  ww w . j a v  a  2s  . c om*/
            .prepareStatement("SELECT client_filename, filename, image_width, image_height, version "
                    + "FROM project_files " + "WHERE link_module_id = ? " + "AND link_item_id = ? ");
    pst.setInt(1, Constants.PROJECT_WIKI_FILES);
    pst.setInt(2, projectId);
    ResultSet rs = pst.executeQuery();
    while (rs.next()) {
        ImageInfo image = new ImageInfo(rs);
        images.put(image.getFilename(), image);
    }
    rs.close();
    pst.close();
    return images;
}

From source file:at.becast.youploader.account.Account.java

public static Account read(String name) throws IOException {
    PreparedStatement stmt;/*from  ww  w.  j a  va  2s.c  o m*/
    try {
        stmt = c.prepareStatement("SELECT * FROM `accounts` WHERE `name`=? LIMIT 1");
        stmt.setString(1, name);
        ResultSet rs = stmt.executeQuery();
        ObjectMapper mapper = new ObjectMapper();
        List<Cookie> c = mapper.readValue(rs.getString("cookie"), new TypeReference<List<Cookie>>() {
        });
        int id = rs.getInt("id");
        String token = rs.getString("refresh_token");
        stmt.close();
        rs.close();
        return new Account(id, name, token, c);
    } catch (SQLException e) {
        LOG.error("Account read error!", e);
        return null;
    }
}

From source file:com.concursive.connect.web.webdav.WebdavManager.java

/**
 * Gets the webdavPassword attribute of the WebdavManager object
 *
 * @param db       Description of the Parameter
 * @param username Description of the Parameter
 * @return The webdavPassword value//from  w w w  .j a  v  a  2s .c  om
 * @throws SQLException Description of the Exception
 */
public static String getWebdavPassword(Connection db, String username) throws SQLException {
    String password = "";
    PreparedStatement pst = db.prepareStatement(
            "SELECT webdav_password " + "FROM users " + "WHERE username = ? " + "AND enabled = ? ");
    pst.setString(1, username);
    pst.setBoolean(2, true);
    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
        password = rs.getString("webdav_password");
    }
    rs.close();
    pst.close();
    return password;
}

From source file:at.becast.youploader.account.Account.java

public static Account read(int id) throws IOException {
    PreparedStatement stmt;// w ww.  j  a v  a  2s .  c  o  m
    try {
        stmt = c.prepareStatement("SELECT * FROM `accounts` WHERE `id`=? LIMIT 1");
        stmt.setInt(1, id);
        ResultSet rs = stmt.executeQuery();
        ObjectMapper mapper = new ObjectMapper();
        List<Cookie> c = mapper.readValue(rs.getString("cookie"), new TypeReference<List<Cookie>>() {
        });
        String name = rs.getString("name");
        String token = rs.getString("refresh_token");
        stmt.close();
        rs.close();
        return new Account(id, name, token, c);
    } catch (SQLException e) {
        LOG.error("Account read error!", e);
        return null;
    }
}

From source file:Main.java

public static long[] getEntryExit(Double id, Calendar date, Connection con, PreparedStatement stmt)
        throws Exception {
    stmt.setDate(1, new java.sql.Date(date.getTimeInMillis()));
    // stmt.setDate(2, new java.sql.Date(date.getTimeInMillis()+1000000));
    stmt.execute();//from ww  w . ja v  a 2s . c  o m
    ResultSet rs = stmt.getResultSet();
    if (rs != null) {

        if (rs.next()) {
            Timestamp d1 = rs.getTimestamp(1);
            Timestamp d2 = rs.getTimestamp(2);
            if (d1 != null && d2 != null) {
                System.out.println(id + ":" + new SimpleDateFormat("dd/MM/yyyy").format(date.getTime()) + ":"
                        + d1.toString());
                long[] res = new long[] { d1.getTime(), d2.getTime() };
                return res;
            }
        }
        rs.close();
    }
    return null;
}

From source file:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.VirtualSQLDataSource.java

private static Set<String> getResult(ResultSet rs, String columnName) {
    Set<String> result = new HashSet<String>();
    try {//from   ww w .j  a  va  2 s.  com
        while (rs.next()) {
            result.add(rs.getString(columnName));
        }
    } catch (Exception ex) {
    }
    ;
    try {
        rs.close();
    } catch (Exception ex) {
    }
    ;
    return result;
}