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.alibaba.druid.benckmark.pool.Oracle_Case4.java

private void printWP_ORDERS(DruidDataSource dataSource) throws SQLException {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM WP_ORDERS");

    JdbcUtils.printResultSet(rs);/* w  w  w. ja  v a2 s  .co  m*/

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

From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java

/**
 * ?????/* w  w  w  .  j  a v a 2 s  .co  m*/
 * @param declNo
 * @return
 */
public static int checkDeclProductPerfect(String declNo) {
    int retCode = -1;
    Connection conn = null;
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_CheckDeclProductPerfect(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error(e);
    } catch (Exception e) {
        log.error(e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error(e);
        }
    }
    return retCode;
}

From source file:io.apiman.gateway.engine.policies.auth.JDBCIdentityValidator.java

/**
 * @see io.apiman.gateway.engine.policies.auth.IIdentityValidator#validate(java.lang.String, java.lang.String, io.apiman.gateway.engine.beans.ServiceRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.async.IAsyncHandler)
 *//*from  ww  w.jav a  2  s .c o m*/
@Override
public void validate(String username, String password, ServiceRequest request, IPolicyContext context,
        JDBCIdentitySource config, IAsyncResultHandler<Boolean> handler) {
    DataSource ds = lookupDatasource(config);
    String sqlPwd = password;
    switch (config.getHashAlgorithm()) {
    case MD5:
        sqlPwd = DigestUtils.md5Hex(password);
        break;
    case SHA1:
        sqlPwd = DigestUtils.shaHex(password);
        break;
    case SHA256:
        sqlPwd = DigestUtils.sha256Hex(password);
        break;
    case SHA384:
        sqlPwd = DigestUtils.sha384Hex(password);
        break;
    case SHA512:
        sqlPwd = DigestUtils.sha512Hex(password);
        break;
    case None:
    default:
        break;
    }
    String query = config.getQuery();
    Connection conn = null;
    boolean validated = false;
    try {
        conn = ds.getConnection();
        conn.setReadOnly(true);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, username);
        statement.setString(2, sqlPwd);
        ResultSet resultSet = statement.executeQuery();
        if (resultSet.next()) {
            validated = true;
        }
        resultSet.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }

    handler.handle(AsyncResultImpl.create(validated));
}

From source file:org.copperengine.core.test.persistent.BaseSpringTxnPersistentWorkflowTest.java

public void testSpringTxnUnitTestWorkflow(String dsContext) throws Exception {
    assumeFalse(skipTests());/*from  ww  w .ja  v  a 2 s .co m*/
    final ConfigurableApplicationContext context = createContext(dsContext);
    cleanDB(context.getBean(DataSource.class));
    final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class);
    final BackChannelQueue backChannelQueue = context.getBean(BackChannelQueue.class);
    try {
        engine.startup();
        engine.run("org.copperengine.core.test.persistent.springtxn.SpringTxnUnitTestWorkflow", "TestData");
        WorkflowResult x = backChannelQueue.dequeue(60, TimeUnit.SECONDS);
        assertNotNull(x);
        assertNotNull(x.getResult());
        assertNull(x.getException());

        // check
        new RetryingTransaction<Void>(context.getBean(DataSource.class)) {
            @Override
            protected Void execute() throws Exception {
                Statement stmt = getConnection().createStatement();
                ResultSet rs = stmt.executeQuery("select count(*) from COP_AUDIT_TRAIL_EVENT");
                assertTrue(rs.next());
                int c = rs.getInt(1);
                assertEquals(7, c);
                rs.close();
                stmt.close();
                return null;
            }
        }.run();
    } finally {
        closeContext(context);
    }
    assertEquals(EngineState.STOPPED, engine.getEngineState());
    assertEquals(0, engine.getNumberOfWorkflowInstances());
}

From source file:mupomat.controller.ObradaOperater.java

@Override
public Operater dodajNovi(Operater entitet) {
    try {//from  ww w. ja va2 s  .co  m
        Connection veza = MySqlBazaPodataka.getConnection();
        PreparedStatement izraz = veza.prepareStatement(
                "insert into operater (korisnickoime,lozinka,ime,prezime,aktivan) values (?,?,?,?,?)",
                Statement.RETURN_GENERATED_KEYS);
        izraz.setString(1, entitet.getKorisnickoIme());
        izraz.setString(2, DigestUtils.md5Hex(entitet.getLozinka()));
        izraz.setString(3, entitet.getIme());
        izraz.setString(4, entitet.getPrezime());
        izraz.setBoolean(5, entitet.isAktivan());
        izraz.executeUpdate();
        ResultSet rs = izraz.getGeneratedKeys();
        rs.next();
        entitet.setSifra(rs.getInt(1));
        rs.close();
        izraz.close();
        veza.close();
    } catch (Exception e) {
        //  System.out.println(e.getMessage());
        e.printStackTrace();
        return null;
    }
    return entitet;
}

From source file:fr.xebia.ws.travel.antifraud.v1_0.AntiFraudServiceImpl.java

private boolean checkDbOnline() {
    try {//  ww  w.j  av a2s. c o  m
        Class.forName("org.hsqldb.jdbc.JDBCDriver");
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e1) {
        e1.printStackTrace();
    }
    try {
        DriverManager.setLoginTimeout(60);
        Connection connection = DriverManager.getConnection(jdbcUrl, user, password);
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT 1 FROM fraud");
        resultSet.next();
        resultSet.close();
        statement.close();
        connection.close();

    } catch (Exception e) {
        return false;
    }

    return true;
}

From source file:hu.petabyte.redflags.engine.gear.indicator.helper.KMonitorInstitutions.java

public void init() {
    if (initialized) {
        return;/*w w  w  . ja  va2 s. c  o  m*/
    }

    if (null == dbhost || null == dbname || null == dbuser || null == dbpass) {
        LOG.warn("K-Monitor Institutions component is not initialized.");
        return;
    }

    try {
        LOG.info("Connecting to K-Monitor database...");
        conn = DriverManager.getConnection(
                String.format("jdbc:mysql://%s/%s?useUnicode=true&characterEncoding=utf-8", dbhost, dbname),
                dbuser, dbpass);
        LOG.info("Querying institutions...");
        PreparedStatement ps = conn.prepareStatement("SELECT name FROM news_institutions");
        ps.execute();
        ResultSet rs = ps.getResultSet();
        while (rs.next()) {
            institutions.add(rs.getString(1));
        }
        rs.close();
        ps.close();
        LOG.info("We have {} institutions", institutions.size());
        conn.close();
    } catch (Exception e) {
        LOG.error("Failed to connect to KMDB.", e);
    }
    initialized = true;
}

From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java

/**
 * ?:?/*ww  w . j  a  v  a2  s . co m*/
 * @return
 */
public static int checkRapidRelease(String declNo) {
    int retCode = -1;
    Connection conn = null;
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_CheckRapidRelease(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N60", e);
    } catch (Exception e) {
        log.error("N61", e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N62", e);
        }
    }
    return retCode;
}

From source file:com.bstek.dorado.core.store.H2BaseStore.java

protected void prepareNamespace() throws Exception {
    Class.forName(driverClassName);
    Connection conn = DriverManager.getConnection(getConnectionUrl(), username, password);
    try {//  www  . j a va  2 s  .c  o  m
        int storeVersion = 0;
        CallableStatement prepareCall = conn.prepareCall("SELECT @storeVersion");
        ResultSet resultSet = prepareCall.executeQuery();
        try {
            if (resultSet.first()) {
                storeVersion = resultSet.getInt("@storeVersion");
            }
        } finally {
            resultSet.close();
            prepareCall.close();
        }

        if (storeVersion < version) {
            logger.info("Initializing store \"" + namespace + "\".");

            prepareCall = conn.prepareCall("SET @storeVersion = " + version);
            try {
                prepareCall.execute();
            } finally {
                prepareCall.close();
            }

            initNamespace(conn);
        }
    } finally {
        conn.close();
    }
}

From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java

public static int checkDeclProductSampling(String declNo) {
    int retCode = -1;
    Connection conn = null;//w  w  w .  j  av a 2  s.  com
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_CheckDeclProductSampling(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N57", e);
    } catch (Exception e) {
        log.error("N58", e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N59", e);
        }
    }
    return retCode;
}