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.splicemachine.derby.utils.SpliceAdminIT.java

@Test
public void testGetActiveServers() throws Exception {
    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_ACTIVE_SERVERS()");
    ResultSet rs = cs.executeQuery();
    TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory
            .convert("call SYSCS_UTIL.SYSCS_GET_ACTIVE_SERVERS()", rs);
    System.out.println(fr.toString());
    Assert.assertTrue(fr.size() >= 1);
    DbUtils.closeQuietly(rs);//from   w w  w . j a va2 s .c  o m
}

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

@Test
public void testGetSchemaInfo() throws Exception {
    String TABLE_NAME = "ZONING2";
    SpliceUnitTest.MyWatcher tableWatcher = new SpliceUnitTest.MyWatcher(TABLE_NAME, CLASS_NAME,
            "(PARCELID INTEGER UNIQUE NOT NULL, ADDRESS VARCHAR(15), BOARDDEC VARCHAR(11), EXSZONE VARCHAR(8), PRPZONE VARCHAR(8), HEARDATE DATE)");
    tableDAO.drop(CLASS_NAME, TABLE_NAME);
    tableWatcher.create(Description.createSuiteDescription(CLASS_NAME, "testGetSchemaInfo"));

    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_SCHEMA_INFO()");
    ResultSet rs = cs.executeQuery();
    TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory
            .convert("call SYSCS_UTIL.SYSCS_GET_SCHEMA_INFO()", rs);
    System.out.println(fr.toString());
    DbUtils.closeQuietly(rs);/*from  ww w. ja  v  a  2 s. c o  m*/
}

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

@Test
@Ignore("DB-5499")
public void testGetWriteIntakeInfo() throws Exception {
    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_WRITE_INTAKE_INFO()");
    ResultSet rs = cs.executeQuery();
    TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory
            .convert("call SYSCS_UTIL.SYSCS_GET_WRITE_INTAKE_INFO()", rs);
    System.out.println(fr.toString());
    Assert.assertTrue(fr.size() >= 1);
    DbUtils.closeQuietly(rs);/*from w  ww .  jav  a 2  s.c om*/
}

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

public List<String> createLastYearReport(ReportParams params) {
    try (Connection connection = OracleJDBCConnector.getConnection();) {
        CallableStatement stmnt = connection.prepareCall("select get_xml_odberatela(?) as xml from dual");
        stmnt.setInt(1, params.getIdOdberatela());
        ResultSet result = stmnt.executeQuery();

        List<String> output = new LinkedList<>();
        while (result.next()) {
            Clob clob = result.getClob("XML");
            Reader reader = clob.getCharacterStream();
            String o = IOUtils.toString(reader);
            output.add(o);//from   ww  w  .  j  a v  a  2  s.  co  m
            File subor = params.getSubor();
            if (subor != null) {
                try (BufferedWriter w = new BufferedWriter(new FileWriter(subor))) {
                    IOUtils.write(o, w);
                }
            }
        }
        return output;
    } catch (SQLException | IOException e) {
        throw new RuntimeException(e);
    }
}

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

@Test
public void testGetRegionServerStatsInfo() throws Exception {
    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_REGION_SERVER_STATS_INFO()");
    ResultSet rs = cs.executeQuery();
    TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory
            .convert("call SYSCS_UTIL.SYSCS_GET_REGION_SERVER_STATS_INFO()", rs);
    System.out.println(fr.toString());
    Assert.assertTrue(fr.size() >= 1);
    DbUtils.closeQuietly(rs);/*from ww w .  j av a  2s .c  o  m*/
}

From source file:org.hyperic.hq.plugin.sybase.SybaseSysmonCollector.java

protected void init() throws PluginException {
    Properties props = getProperties();

    Connection c = null;/*  w w w  .ja  va 2 s. co m*/
    ResultSet rs = null;
    CallableStatement st = null;
    String sa_role = SybaseProductPlugin.getSaRole();

    try {
        c = createConnection(props);
        st = c.prepareCall("{call sp_displayroles}");
        rs = st.executeQuery();
        boolean roleOK = false;
        while (rs.next() && !roleOK) {
            roleOK = rs.getString(1).equals(sa_role);
        }
        if (!roleOK) {
            throw new PluginException(
                    "Could not connect using information provided: The user must have System Administrator ('"
                            + sa_role + "') role");
        }
    } catch (SQLException e) {
        throw new PluginException("Could not connect using information provided", e);
    } finally {
        DBUtil.closeJDBCObjects(log, c, st, rs);
    }

    String interval = props.getProperty(SybaseSysmonCollector.INTERVAL);
    Pattern p = Pattern.compile("^\\d\\d:\\d\\d:\\d\\d$");
    Matcher m = p.matcher(interval);
    if (!m.matches()) {
        String msg = "Configuration failed: bad INTERVAL format ##:##:## (" + interval + ")";
        throw new PluginException(msg);
    }

    super.init();
}

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

@Test
@Category(SlowTest.class)
public void testGetSchemaInfoSplit() throws Exception {
    int size = 100;
    String TABLE_NAME = "SPLIT";
    SpliceUnitTest.MyWatcher tableWatcher = new SpliceUnitTest.MyWatcher(TABLE_NAME, CLASS_NAME,
            "(username varchar(40) unique not null,i int)");
    tableDAO.drop(CLASS_NAME, TABLE_NAME);
    tableWatcher.create(Description.createSuiteDescription(CLASS_NAME, "testGetSchemaInfoSplit"));
    try {/*  w ww  .j a va2s.c  o m*/
        PreparedStatement ps = spliceClassWatcher
                .prepareStatement(String.format("insert into %s.%s values (?,?)", CLASS_NAME, TABLE_NAME));
        for (int i = 0; i < size; i++) {
            ps.setInt(1, i);
            ps.setString(2, Integer.toString(i + 1));
            ps.executeUpdate();
        }
        //            spliceClassWatcher.splitTable(TABLE_NAME,CLASS_NAME,size/3);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        spliceClassWatcher.closeAll();
    }

    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_SCHEMA_INFO()");
    ResultSet rs = cs.executeQuery();
    TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory
            .convert("call SYSCS_UTIL.SYSCS_GET_SCHEMA_INFO()", rs);
    System.out.println(fr.toString());
    DbUtils.closeQuietly(rs);
}

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

@Test
@Category(SlowTest.class)
public void testCallSQLTABLESInAppSchema() throws Exception {
    CallableStatement cs = methodWatcher.prepareCall("call SYSIBM.SQLTABLES(null,'"
            + CallStatementOperationIT.class.getSimpleName().toUpperCase() + "',null,null,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 ww.j a va  2  s  . c  o m*/
    }
    Assert.assertTrue("Incorrect rows returned!", count > 0);
    DbUtils.closeQuietly(rs);
}

From source file:com.ing.connector.newbus.WPendingOverridesImpl.java

/**
 * This method will query the database and create an Odd string that
 * represents the collection of agent overrides.
 *///from  w w w . j  ava2  s. c o m
public WResult getObject(WObjectKeys keys) {
    String policyId = keys.getStringKey(1);
    String agentSystemSource = keys.getStringKey(2); //JFG2.0
    String companyId = keys.getStringKey(3); //JFG4.0
    String agentParm = keys.getStringKey(4); //CSST400
    String driverSystemSource = getDriver().getSystemSource(); //JFG2.0
    String driverTableType = getDriver().getTableType(); //DIL3.0
    String databaseName = "scldbali"; //DIL3.0
    String procedureName = null; //DIL3.0
    String userType = keys.getStringKey(5);
    String agentName;

    com.ing.connector.Registrar.logInfoMessage("wpendingoverridesimpl - userType" + userType);

    WResult result = new WResult();

    WCollection collection = new WCollection("com.ing.connector.model.WAgentOverrideExt");

    result.setModelObject(collection);

    if (!agentSystemSource.equals(driverSystemSource)) //JFG2.0
    {
        result.setStatus(WResult.OBJECT_NOT_FOUND);
        return result;
    }

    if (userType != null && userType.equalsIgnoreCase("internalUser"))
        databaseName = LookUp.getInstance().getStringProperty("Connector.History.Database");
    ;

    // March 2004 deleted int connNo = line

    Connection con = getConnection();
    // March 2004 removed param

    if (driverTableType.equals(TABLETYPECOPY)) //DIL3.0
    { //DIL3.0

        procedureName = "bali_WAgentOverrides_get_p"; //DIL3.0
    } //DIL3.0
    else //DIL3.0
    { //DIL3.0
        //databaseName = "scldpt";                        //RL-004454 RSD 

        procedureName = "bali_WAgentOverridesImpl"; //DIL3.0
    } //DIL3.0
    com.ing.connector.Registrar.logInfoMessage("wpendingoverridesimpl - databaseName" + databaseName);
    com.ing.connector.Registrar.logInfoMessage("wpendingoverridesimpl - procedureName" + procedureName);
    try {
        Statement stmt = con.createStatement();
        //DIL3.0            stmt.execute("use " + "scldpt");
        stmt.execute("use " + databaseName);
        Registrar.logInfoMessage("exec " + procedureName + " " + policyId + "," + agentParm);
        //DIL3.0            CallableStatement cstmt = con.prepareCall("{call bali_WAgentOverridesImpl(?)}");
        CallableStatement cstmt = con.prepareCall("{call " + procedureName + "(?,?)}"); //CSST400
        cstmt.setString(1, policyId);
        cstmt.setString(2, agentParm); //CSST400

        ResultSet rs = cstmt.executeQuery();

        WDateIsoFormat isoFormat = new WDateIsoFormat();

        while (rs.next()) {

            WAgentOverrideExt single = new WAgentOverrideExt(getDriverName(), getImplTypeName());

            single.setAgentId(rs.getString("agent_number"));
            agentName = new String(rs.getString("agent_name"));
            //RL-009402 - SXL - START
            String formattedAgentName = WStringUtil.formatAgentName(agentName);

            single.setFormattedAgentName(formattedAgentName);

            if (StringUtils.countMatches(agentName, ",") == 2) {
                String lastName = agentName.substring(0, agentName.indexOf(",")).trim();
                String firstName = (agentName.substring(agentName.indexOf(",") + 1, agentName.lastIndexOf(",")))
                        .trim();
                String middleName = (agentName.substring(agentName.lastIndexOf(",") + 1)).trim();
                single.setLastName(lastName);
                single.setFirstName(firstName);
                single.setMiddleName(middleName);
            } else {
                //RL-009402 - SXL - END  
                int i = agentName.indexOf(',');
                if (i != -1) {
                    single.setLastName(agentName.substring(0, i).trim());
                    single.setFirstName(agentName.substring(i + 1).trim());
                } else {
                    single.setLastName(agentName);
                }
            }

            single.setOverridePercent(rs.getDouble("commission_split"));
            single.setContractType(rs.getString("agent_contract_typ"));
            single.setOverrideId(rs.getString("ovr_agent_number")); //CSST400
            single.setOverrideAgentName(rs.getString("ovr_agent_name")); //   KLN/02/13/07//RL-001655    
            single.setLevel(rs.getString("Hierarchy_Type")); //RL-005642 LXJ added
            collection.addElement(single);
        }

        rs.close();
        cstmt.close();
        stmt.close();

        result.setModelObject(collection);

        if (collection.size() == 0) {
            result.setStatus(WResult.OBJECT_NOT_FOUND);
        }

    } catch (SQLException sqle) {
        result.setException(sqle);
        com.ing.connector.Registrar.logError(getClass().getName() + ": " + sqle.getMessage());
    } catch (Exception exc) {
        result.setException(exc);
        com.ing.connector.Registrar.logError(getClass().getName() + ": " + exc.getMessage());
    }

    releaseConnection(con);
    //March 2004 changed param from connNo to con

    return result;

}

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

@Test
public void testGetSetLogLevel() throws Exception {
    String logger = "com.splicemachine.derby.iapi.sql.execute.SpliceOperationContext";
    String origLevel = "FRED";
    String newLogLevel = "INFO";
    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_LOGGER_LEVEL(?)");
    cs.setString(1, logger);//from  w  w  w .ja  v  a 2  s. co m
    ResultSet rs = cs.executeQuery();
    while (rs.next()) {
        origLevel = rs.getString(1);
    }

    try {
        cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_SET_LOGGER_LEVEL(?,?)");
        cs.setString(1, logger);
        cs.setString(2, newLogLevel);
        cs.execute();

        cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_LOGGER_LEVEL(?)");
        cs.setString(1, logger);
        rs = cs.executeQuery();
        String currentLogLevel = "FRED";
        while (rs.next()) {
            currentLogLevel = rs.getString(1);
        }
        Assert.assertNotEquals("FRED", currentLogLevel);
        Assert.assertEquals(newLogLevel, currentLogLevel);
    } finally {
        // reset to orig value
        cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_SET_LOGGER_LEVEL(?,?)");
        cs.setString(1, logger);
        cs.setString(2, origLevel);
        cs.execute();
    }

    DbUtils.closeQuietly(rs);

}