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:com.oic.net.Callback.java

private void registerData(String studentNumber, String key, HttpSession session) {
    Connection con = null;/*from  w  w  w  .  jav  a 2s.  c o m*/
    PreparedStatement ps = null;
    try {
        String sql = "SELECT * FROM user WHERE studentnumber = ?";
        con = DatabaseConnection.getConnection();
        ps = con.prepareStatement(sql);
        ps.setString(1, studentNumber);
        ResultSet rs = ps.executeQuery();
        if (!rs.next()) {
            rs.close();
            ps.close();
            con.close();
            session.setAttribute("alreadyId", false);
            return;
        }
        rs.close();
        ps.close();
        sql = "UPDATE user SET secretkey = ? WHERE studentnumber = ? ";
        ps = con.prepareStatement(sql);
        ps.setString(1, key);
        ps.setString(2, studentNumber);
        ps.executeUpdate();
        ps.close();
        session.setAttribute("alreadyId", true);
    } catch (SQLException e) {
        try {
            ps.close();
        } catch (Exception e1) {
        }
    }
}

From source file:com.linkedin.pinot.integration.tests.RealtimeClusterIntegrationTest.java

@BeforeClass
public void setUp() throws Exception {
    // Start ZK and Kafka
    startZk();//from   w  w w .j  ava2 s  .c  om
    kafkaStarters = KafkaStarterUtils.startServers(getKafkaBrokerCount(), KafkaStarterUtils.DEFAULT_KAFKA_PORT,
            KafkaStarterUtils.DEFAULT_ZK_STR, KafkaStarterUtils.getDefaultKafkaConfiguration());

    // Create Kafka topic
    createKafkaTopic(KAFKA_TOPIC, KafkaStarterUtils.DEFAULT_ZK_STR);

    // Start the Pinot cluster
    startController();
    startBroker();
    startServer();

    // Unpack data
    final List<File> avroFiles = unpackAvroData(_tmpDir, SEGMENT_COUNT);

    File schemaFile = getSchemaFile();

    // Load data into H2
    ExecutorService executor = Executors.newCachedThreadPool();
    setupH2AndInsertAvro(avroFiles, executor);

    // Initialize query generator
    setupQueryGenerator(avroFiles, executor);

    // Push data into the Kafka topic
    pushAvroIntoKafka(avroFiles, executor, KAFKA_TOPIC);

    // Wait for data push, query generator initialization and H2 load to complete
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.MINUTES);

    // Create Pinot table
    setUpTable("mytable", "DaysSinceEpoch", "daysSinceEpoch", KafkaStarterUtils.DEFAULT_ZK_STR, KAFKA_TOPIC,
            schemaFile, avroFiles.get(0));

    // Wait until the Pinot event count matches with the number of events in the Avro files
    long timeInFiveMinutes = System.currentTimeMillis() + 5 * 60 * 1000L;
    Statement statement = _connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    statement.execute("select count(*) from mytable");
    ResultSet rs = statement.getResultSet();
    rs.first();
    int h2RecordCount = rs.getInt(1);
    rs.close();

    waitForRecordCountToStabilizeToExpectedCount(h2RecordCount, timeInFiveMinutes);
}

From source file:com.naver.timetable.jdbc.CubridDataManager.java

public void close(ResultSet rs) {
    try {/*w w  w. j a  va  2s  .  co m*/
        if (rs != null) {
            rs.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.sf.ddao.ops.SelectSqlOperation.java

public Object exec(Context context, Object[] args) throws StatementFactoryException, SQLException {
    PreparedStatement preparedStatement = statementFactory.createStatement(context, false);
    ResultSet resultSet = preparedStatement.executeQuery();
    RSMapper RSMapper = rsMapperFactory.getInstance(args, resultSet);
    final Object res = RSMapper.handle(context, resultSet);
    resultSet.close();
    preparedStatement.close();/*from   ww  w  .  j  a v a  2 s  . c o  m*/
    return res;
}

From source file:JDBCUtil.java

/**
 * Closes database result set and logs if an error
 * is encountered/*from  w ww.j a v a  2s  .  co m*/
 *
 * @param aResultSet the result set to be closed
 */
public void closeJDBCResultSet(ResultSet aResultSet) {
    try {
        if (aResultSet != null) {
            aResultSet.close();
        }
    } catch (SQLException sqle) {
        // Log exception and continue
        subclassLogWrapper("Unexpected exception while closing database result set.");
    }
}

From source file:com.att.pirates.controller.GlobalDataController.java

public static boolean isATTEmployeeITUPRoleEmpty(String UUID) {
    ResultSet rs = null;
    Connection conn = null;/*from   w  w  w  . ja v  a  2s .c  o m*/
    PreparedStatement preparedStatement = null;
    boolean rc = false;

    try {
        conn = DBUtility.getDBConnection();
        // SQL query command
        String SQL = "  select * from ATTEmployeeArtifacts where uuid = ? ";

        preparedStatement = conn.prepareStatement(SQL);
        preparedStatement.setString(1, UUID);
        rs = preparedStatement.executeQuery();

        if (rs.next()) {
            rc = true;
        }
    } catch (SQLException e) {
        logger.error(e.getMessage());
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        try {
            if (rs != null)
                rs.close();
        } catch (Exception e) {
        }
        ;
        try {
            if (preparedStatement != null)
                preparedStatement.close();
        } catch (Exception e) {
        }
        ;
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
        ;
    }

    return rc;
}

From source file:com.jaspersoft.jasperserver.war.CSVServlet.java

private void printQuery(String sqlQuery, Connection conn, PrintWriter out) {
    log.info("drill-through SQL = " + sqlQuery);
    try {//from w w  w. j  a v  a2  s  . c om
        Statement s = conn.createStatement();
        ResultSet rs = s.executeQuery(sqlQuery);
        printCSV(rs, out);
        rs.close();
    } catch (Exception e) {
        e.printStackTrace();
        log.error(e);
    } finally {
        try {
            conn.close();
        } catch (SQLException sqle) {
            sqle.printStackTrace();
            log.error(sqle);
        }
    }
}

From source file:com.pactera.edg.am.metamanager.extractor.dao.impl.TargetDBInfoDaoImpl.java

private int getColumnSize(DatabaseMetaData metaData, String schema, String table, String column)
        throws SQLException {
    ResultSet rs = metaData.getColumns(null, schema, table, column);
    int columnSize = -1;
    while (rs.next()) {
        columnSize = rs.getInt(Column.COLUMN_SIZE) / 3;
    }/*  w  w  w . ja va 2s . c  o  m*/
    rs.close();
    return columnSize;
}

From source file:com.tesora.dve.sql.SQLVariableTest.java

private static String getCurrentGlobalValue(DBHelper helper, String varName) throws Throwable {
    ResultSet rs = null;
    String out = null;/* www  .  ja  v  a  2s .  c o  m*/
    try {
        if (helper.executeQuery("select @@global." + varName)) {
            rs = helper.getResultSet();
            if (!rs.next())
                fail("Variable " + varName + " apparently does not exist on native");
            out = rs.getString(1);
        }
    } finally {
        if (rs != null)
            rs.close();
    }
    return out;
}

From source file:com.alibaba.druid.benckmark.pool.Oracle_Case4.java

private void printAV_INFO(DataSource dataSource) throws SQLException {
    String sql = "SELECT DISTINCT ID FROM AV_INFO WHERE ROWNUM <= 10";
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sql);

    JdbcUtils.printResultSet(rs);/*  www  .j  a  v a 2  s .  co m*/

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