Example usage for java.sql CallableStatement executeQuery

List of usage examples for java.sql CallableStatement executeQuery

Introduction

In this page you can find the example usage for java.sql CallableStatement executeQuery.

Prototype

ResultSet executeQuery() throws SQLException;

Source Link

Document

Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.

Usage

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 {//from  w  ww  .  j ava 2s.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:net.sf.jdbcwrappers.trim.TrimmingTest.java

@Test
public void testCallableStatement() throws SQLException {
    CallableStatement statement = connection.prepareCall("{ call TESTPROC() }");
    try {/*w  w  w  . j  a v a2 s . co m*/
        ResultSet rs = statement.executeQuery();
        rs.next();
        assertEquals("test", rs.getString(2));
        assertEquals("test", rs.getString("CHAR_COL"));
    } finally {
        statement.close();
    }
}

From source file:com.splicemachine.derby.impl.sql.execute.operations.CallStatementOperationIT.java

@Test
public void testCallSysSchemas() throws Exception {
    methodWatcher.getOrCreateConnection().setAutoCommit(true);
    CallableStatement cs = methodWatcher.prepareCall("CALL SYSIBM.METADATA()");
    ResultSet rs = cs.executeQuery();
    int count = 0;
    while (rs.next()) {
        Assert.assertTrue(rs.getBoolean(1));
        count++;//www . j  a va 2 s .  co m
    }
    Assert.assertEquals(1, count);
    DbUtils.closeQuietly(rs);
}

From source file:com.splicemachine.derby.impl.sql.execute.operations.CallStatementOperationIT.java

@Test
public void testCallGetTypeInfo() throws Exception {
    String[] expectedTypes = { "BIGINT", "LONG VARCHAR FOR BIT DATA", "VARCHAR () FOR BIT DATA",
            "CHAR () FOR BIT DATA", "LONG VARCHAR", "CHAR", "NUMERIC", "DECIMAL", "INTEGER", "SMALLINT",
            "FLOAT", "REAL", "DOUBLE", "VARCHAR", "BOOLEAN", "DATE", "TIME", "TIMESTAMP", "OBJECT", "BLOB",
            "CLOB", "XML" };
    Arrays.sort(expectedTypes);//from w w w  . j  a v a  2  s . c om

    CallableStatement cs = methodWatcher.prepareCall("call SYSIBM.SQLGETTYPEINFO(0,null)");
    ResultSet rs = cs.executeQuery();
    try {
        List<String> actual = new ArrayList<>(expectedTypes.length);
        while (rs.next()) {
            actual.add(rs.getString(1));
        }
        String[] actualArray = actual.toArray(new String[actual.size()]);
        Arrays.sort(actualArray);
        Assert.assertArrayEquals(expectedTypes, actualArray);
    } finally {
        DbUtils.closeQuietly(rs);
    }
}

From source file:com.splicemachine.derby.impl.sql.catalog.SqlStatisticsIT.java

private int getResultSetCountFromShowIndexes(String schemaName, String tableName) throws Exception {
    if (schemaName == null) {
        schemaName = "null";
    } else {/*from  w  w w  .  j a v a  2s  .  c om*/
        schemaName = "'" + schemaName + "'";
    }
    if (tableName == null) {
        tableName = "null";
    } else {
        tableName = "'" + tableName + "'";
    }
    CallableStatement cs = methodWatcher.prepareCall(
            format("call SYSIBM.SQLSTATISTICS(null, %s, %s, 1, 1, null)", schemaName, tableName),
            ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = cs.executeQuery();
    int count = 0;
    LOG.trace(format("Show Indexes Args: schema = %s, table = %s", schemaName, tableName));
    while (rs.next()) {
        String schema = rs.getString("TABLE_SCHEM");
        String table = rs.getString("TABLE_NAME");
        String index = rs.getString("INDEX_NAME");
        String column = rs.getString("COLUMN_NAME");
        int position = rs.getInt("ORDINAL_POSITION");
        LOG.trace(
                format("Show Indexes Results: schema = %s, table = %s, index = %s, column = %s, position = %s",
                        schema, table, index, column, position));
        count++;
    }
    LOG.trace(format("Show Indexes Results: count = %s", count));
    DbUtils.closeQuietly(rs);
    return count;
}

From source file:com.splicemachine.derby.impl.sql.execute.operations.CallStatementOperationIT.java

@Test
public void testCallSQLTABLES() throws Exception {
    CallableStatement cs = methodWatcher.prepareCall(
            "call SYSIBM.SQLTABLES(null,'SYS',null,'SYSTEM TABLE',null)", ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = cs.executeQuery();
    int count = 0;
    while (rs.next()) {
        Object data = rs.getObject(2);
        count++;//from   w w w  .j  a  v a  2 s  .  com
    }
    Assert.assertTrue("Incorrect rows returned!", count > 0);
    DbUtils.closeQuietly(rs);
}

From source file:com.splicemachine.derby.utils.SpliceAdminIT.java

@Test
public void testGetLoggers() throws Exception {
    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_LOGGERS()");
    ResultSet rs = cs.executeQuery();
    TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory
            .convert("call SYSCS_UTIL.SYSCS_GET_LOGGERS()", rs);
    System.out.println(fr.toString());
    Assert.assertTrue(fr.size() >= 80);
    DbUtils.closeQuietly(rs);//from ww w  .  j av  a2  s. c  om
}

From source file:com.splicemachine.derby.utils.SpliceAdminIT.java

@Test
public void testGetRequests() throws Exception {
    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_REQUESTS()");
    ResultSet rs = cs.executeQuery();
    TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory
            .convert("call SYSCS_UTIL.SYSCS_GET_REQUESTS()", rs);
    System.out.println(fr.toString());
    Assert.assertTrue(fr.size() >= 1);
    DbUtils.closeQuietly(rs);/*w  w w .j a  v  a2  s.co  m*/
}

From source file:sk.uniza.fri.pds.spotreba.energie.service.SeHistoriaService.java

@Override
public List<SeHistoria> findAll() {
    try (Connection connection = OracleJDBCConnector.getConnection();) {
        CallableStatement stmnt = connection
                .prepareCall("SELECT * FROM SE_HISTORIA ORDER BY CISLO_ODBERATELA ASC, CIS_ZARIADENIA");
        ResultSet result = stmnt.executeQuery();
        List<SeHistoria> output = new LinkedList<>();
        while (result.next()) {
            SeHistoria o = new SeHistoria();
            o.setCisZariadenia(result.getInt("CIS_ZARIADENIA"));
            o.setCisloOdberatela(result.getInt("CISLO_ODBERATELA"));
            o.setDatumInstalacie(result.getDate("DATUM_INSTALACIE"));
            o.setDatumOdobratia(result.getDate("DATUM_ODOBRATIA"));
            output.add(o);// w  ww  . j a  v a 2s  .  c  om
        }
        return output;
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.splicemachine.derby.utils.SpliceAdminIT.java

@Test
public void testGetSpliceVersion() throws Exception {
    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_VERSION_INFO()");
    ResultSet rs = cs.executeQuery();
    TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory
            .convert("call SYSCS_UTIL.SYSCS_GET_VERSION_INFO()", rs);
    System.out.println(fr.toString());
    Assert.assertTrue(fr.size() >= 1);
    DbUtils.closeQuietly(rs);/*  www. jav a2  s. co m*/
}