Java Code Examples for java.sql.CallableStatement#execute()

The following examples show how to use java.sql.CallableStatement#execute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallableTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Calls a SQL procedure that populates OUT parameters with minimum, 
 * maximum, and null values fetched from a table with numeric columns. 
 * Pre-history: long, long ago this test was added to exercise a problem
 * with converting BigDecimal to packed decimal, which left the Network 
 * Server cpu bound.
 * Excluded from environments than don't have JDBC 2 DriverManager.
 * Excluded from JSR169/j2ME, which doesn't support get/set BigDecimal yet.
 * @throws SQLException 
 */
public void xtestNumericBoundariesProc() throws SQLException
{
    // Populate the test table
    String SqlStatement= 
        "insert into NUMERIC_BOUNDARIES_TABLE " +
        "values(999999999999999, 0.000000000000001, null)";
    Statement stmt = createStatement();
    stmt.executeUpdate(SqlStatement);

    // SELECT the values back by calling the SQL procedure.
    CallableStatement cstmt = prepareCall(
        "CALL NUMERIC_BOUNDARIES_PROC(?,?,?)");
    cstmt.registerOutParameter(1,java.sql.Types.NUMERIC,15);
    cstmt.registerOutParameter(2,java.sql.Types.NUMERIC,15);
    cstmt.registerOutParameter(3,java.sql.Types.NUMERIC,15);

    cstmt.execute();

    assertDecimalSameValue("OUT 1", "999999999999999.000000000000000", 
        cstmt.getBigDecimal(1));
    assertDecimalSameValue("OUT 2", "0.000000000000001", 
        cstmt.getBigDecimal(2));
    assertNull("Expected OUT 3 to be null", cstmt.getBigDecimal(3));

}
 
Example 2
Source File: GeneralProcedure.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected  ResultSet[] callProcedure(Connection conn , Object[] inOut) throws SQLException { 
  ResultSet[] rs = new ResultSet[getOutputResultSetCount()];
  CallableStatement cs = null;
  if (GenericDMLHelper.isDerby(conn)) {
     cs = getDerbyCallableStatement(conn);
  }
  else {
     cs = getCallableStatement(conn);
  }    
  cs.execute();     
  rs = getOutputValues(cs, inOut);   
  SQLWarning warning = cs.getWarnings(); //test to see there is a warning
  if (warning != null) {
    SQLHelper.printSQLWarning(warning);
  } 
  return rs;
}
 
Example 3
Source File: ClobStoredProcedureTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Tests the SYSIBM.CLOBRELEASELOCATOR stored procedure.
 *
 * @throws SQLException
 */
public void testClobReleaseLocatorSP() throws SQLException {
    CallableStatement cs  = prepareCall
        ("CALL SYSIBM.CLOBRELEASELOCATOR(?)");
    cs.setInt(1, 1);
    cs.execute();
    cs.close();

    //once the locator has been released the CLOBGETLENGTH on that
    //locator value will throw an SQLException. This assures that
    //the locator has been properly released.

    cs  = prepareCall
        ("? = CALL SYSIBM.CLOBGETLENGTH(?)");
    cs.registerOutParameter(1, java.sql.Types.BIGINT);
    cs.setInt(2, 1);
    try {
        cs.executeUpdate();
    } catch(SQLException sqle) {
        //on expected lines. The test was successful.
        return;
    }
    //The exception was not thrown. The test has failed here.
    fail("Error the locator was not released by SYSIBM.CLOBRELEASELOCATOR");
    cs.close();
}
 
Example 4
Source File: ProcedureTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private void closeCurrentGetMoreResults(CallableStatement cs, ResultSet[] allRS) throws SQLException {
    cs.execute();
    
    for (int i = 0; i < 5; i++)
    {
        allRS[i] = cs.getResultSet();
        assertSame(cs, allRS[i].getStatement());
        allRS[i].next();
        assertEquals(2+i, allRS[i].getInt(1));
        
        if (i < 4)
            assertTrue(cs.getMoreResults(Statement.CLOSE_CURRENT_RESULT));
        else
            assertFalse(cs.getMoreResults(Statement.CLOSE_CURRENT_RESULT));
    }
    
    // verify resultSets are closed
    for (int i = 0; i < 5; i++)
        JDBC.assertClosed(allRS[i]);
}
 
Example 5
Source File: TMDatabaseImpl.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 将TMX的header接点的主要属性写入到mheader表中
 * @throws SQLException
 */
public String insertHeader(Hashtable<String, String> params) throws SQLException {
	CallableStatement stmt = null;
	try {
		String sql = dbConfig.getOperateDbSQL("insert-mheader");
		stmt = conn.prepareCall(sql);
		int i = 1;
		stmt.setString(i++, params.get("CREATIONTOOL"));
		stmt.setString(i++, params.get("CTVERSION"));
		stmt.setString(i++, params.get("TMF"));
		stmt.setString(i++, params.get("SRCLANG"));
		stmt.setString(i++, params.get("ADMINLANG"));
		stmt.setString(i++, params.get("DATATYPE"));
		stmt.setString(i++, params.get("SEGTYPE"));
		stmt.setString(i++, params.get("CREATIONID"));
		stmt.setString(i++, params.get("CREATIONDATE"));
		stmt.setString(i++, params.get("CHANGEID"));
		stmt.setString(i++, params.get("CHANGEDATE"));
		stmt.setString(i++, params.get("ENCODING"));
		stmt.registerOutParameter(i++, Types.INTEGER);
		stmt.execute();
		return stmt.getString(i - 1);
	} finally {
		if (stmt != null) {
			stmt.close();
		}
	}
}
 
Example 6
Source File: CallableTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Calls a SQL procedure that outputs a message with System.out.println.
 * Converted from the original test, but initially disabled because of the
 * message output to system out. Easily enabled by changing method name to
 * remove the initial "norun_" (the name becomes testSystemOutPrintlnProc).
 * @throws SQLException 
 */
public void norun_testSystemOutPrintlnProc() throws SQLException
{
    CallableStatement cs = prepareCall
        ("call SYSTEM_OUT_PRINTLN_PROC()");
    cs.execute();
    cs.close();
}
 
Example 7
Source File: CallableTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Calls a SQL procedure that takes non-numeric IN and OUT parameters.
 * @throws SQLException 
 */
public void testNonNumericTypesInAndOutProc() throws SQLException
{
    CallableStatement cs = prepareCall
        ("call NON_NUMERIC_TYPES_IN_AND_OUT_PROC(?,?,?,?,?,?,?,?)");

    cs.setDate(1, Date.valueOf("2002-05-12"));
    cs.setTime(2, Time.valueOf("10:05:02"));
    cs.setTimestamp(3, Timestamp.valueOf("2002-05-12 10:05:02.000000000"));
    byte[] ba = new byte[2];
    ba[0] = 1;
    ba[1] = 2;
    cs.setBytes(4, ba);

    cs.registerOutParameter (5, java.sql.Types.DATE);
    cs.registerOutParameter (6, java.sql.Types.TIME);
    cs.registerOutParameter (7, java.sql.Types.TIMESTAMP);
    cs.registerOutParameter (8, java.sql.Types.VARBINARY);

    cs.execute();

    assertEquals("OUT date", Date.valueOf("2002-05-12"), cs.getDate(5));
    assertEquals("OUT time"  , Time.valueOf("10:05:02"), cs.getTime(6));
    assertEquals("OUT timestamp" , 
        Timestamp.valueOf("2002-05-12 10:05:02.000000000"), 
        cs.getTimestamp(7));
    assertTrue(Arrays.equals(ba, cs.getBytes(8)));
}
 
Example 8
Source File: AuthenticationTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected void setDatabaseProperty(
    String propertyName, String value, Connection conn) 
throws SQLException {
    CallableStatement setDBP =  conn.prepareCall(
    "CALL SYSCS_UTIL.SET_DATABASE_PROPERTY(?, ?)");
    setDBP.setString(1, propertyName);
    setDBP.setString(2, value);
    setDBP.execute();
    setDBP.close();
}
 
Example 9
Source File: PGDbWriteAccess.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void insertUserActivityStatistics( int testCaseId, String machine, String statisticIds,
                                          String statisticValues, long timestamp,
                                          boolean closeConnection ) throws DatabaseAccessException {

    timestamp = inUTC(timestamp);

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection
                                      .prepareCall("{ call sp_insert_user_activity_statistic_by_ids(?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, testCaseId);
        callableStatement.setString(2, machine);
        callableStatement.setString(3, statisticIds);
        callableStatement.setString(4, statisticValues);
        callableStatement.setTimestamp(5, new Timestamp(timestamp));

        callableStatement.execute();

    } catch (Exception e) {
        String errMsg = "Unable to insert user activity statistics, statistic IDs '" + statisticIds
                        + "', statistic values '" + statisticValues + "', timestamp " + timestamp;
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 10
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static void setDatabaseProperty(String property, String value) 
throws SQLException
{
    DataSource ds = JDBCDataSource.getDataSource();
    Connection cadmin = ds.getConnection();
    CallableStatement cs = cadmin.prepareCall(
        "CALL SYSCS_UTIL.SET_DATABASE_PROPERTY(?, ?)");
    cs.setString(1, property);
    cs.setString(2, value);
    cs.execute();
    
    cs.close();
    cadmin.close();
}
 
Example 11
Source File: ResultSetsFromPreparedStatementTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test CallStatementResultSet
 */
public void testCallStatementResultSet() throws Exception {
    // CallStatementResultSet
    CallableStatement cs = prepareCall
        ("call SYSCS_UTIL.SET_DATABASE_PROPERTY(?, ?)");
    cs.setString(1, "some.property.name");
    PreparedStatement ps = prepareStatement
        ("values SYSCS_UTIL.GET_DATABASE_PROPERTY"+
         "('some.property.name')");
    for (int i = 0; i < 20; ++i) {
        final Integer I = new Integer(i);
        cs.setObject(2, I);
        cs.execute();
        ResultSet rs = ps.executeQuery();
        assertResultSet("i=?="+i, new Object[][] {
                            { I.toString() }
                        }, rs);
        // Re-execute cs with the same parameter
        cs.execute();
        rs = ps.executeQuery();
        assertResultSet("Ri=?="+i, new Object[][] {
                            { I.toString() }
                        }, rs);

    }
    cs.close();
    ps.close();
}
 
Example 12
Source File: DAProcedures.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected static void callProcedureSellordersSGUpdate(Connection conn, String sql, 
   Timestamp orderTime, int tid) throws SQLException { 
  CallableStatement cs = null;
  cs = conn.prepareCall(sql);
  Log.getLogWriter().info(sql + " with order_time: " + orderTime + " and with tid: " + tid );
  cs.setTimestamp(1, orderTime);
  cs.setInt(2, tid);
  cs.execute();
 
  SQLWarning warning = cs.getWarnings(); //test to see there is a warning
  if (warning != null) {
    SQLHelper.printSQLWarning(warning);
  } 
}
 
Example 13
Source File: JdbcTestBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
static void startAsyncEventListener(String ID, Connection conn) throws SQLException {

    try {
      if (conn == null) {
        conn = getConnection();
      }
      CallableStatement cs = conn
          .prepareCall("call SYS.START_ASYNC_EVENT_LISTENER (?)");
      cs.setString(1, ID);
      cs.execute();
    } catch (SQLException sqle) {
      throw GemFireXDRuntimeException.newRuntimeException(null, sqle);
    }
  }
 
Example 14
Source File: NamedPreparedStatement.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the CallableStatement using the given values for bind parameters.
 * @param cs The CallableStatement to execute
 * @param parameterMap The Map returned setup by replaceBindParams
 * @param inParams A map of parameter name to input value to bind to the
 *                 statement.
 * @param outParams A map of parameter name to Integer object of
 *                  SQL Types representing the type of data to be returned.
 * @return true if CallableStatement executed without error, false otherwise.
 * @throws RuntimeException in case of SQLException
 */
public static boolean execute(CallableStatement cs,
        Map<String, List<Integer>> parameterMap,
        Map<String, ?> inParams, Map<String, Integer> outParams)
        throws RuntimeException {
    try {
        setVars(cs, parameterMap, inParams);
        setOutputVars(cs, parameterMap, outParams);
        return cs.execute();
    }
    catch (SQLException e) {
        throw SqlExceptionTranslator.sqlException(e);
    }
}
 
Example 15
Source File: CallableStatementRegressionTest.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
public void testHugeNumberOfParameters() throws Exception {
    if (!serverSupportsStoredProcedures()) {
        return;
    }

    StringBuilder procDef = new StringBuilder("(OUT param_0 VARCHAR(32)");
    StringBuilder placeholders = new StringBuilder("?");

    for (int i = 1; i < 274; i++) {
        procDef.append(", OUT param_" + i + " VARCHAR(32)");
        placeholders.append(",?");
    }
    procDef.append(")\nBEGIN\nSELECT 1;\nEND");

    createProcedure("testHugeNumberOfParameters", procDef.toString());

    CallableStatement cStmt = null;

    try {
        cStmt = this.conn.prepareCall("{call testHugeNumberOfParameters(" + placeholders.toString() + ")}");
        cStmt.registerOutParameter(274, Types.VARCHAR);

        cStmt.execute();
    } finally {
        if (cStmt != null) {
            cStmt.close();
        }
    }
}
 
Example 16
Source File: GfxdLRUDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testReplicatedRegionLRUHeapPercOverflow() throws Exception {
  startVMs(1, 1);
  clientSQLExecute(
      1," create diskstore teststore 'temp' ");
  clientSQLExecute(
      1,
      " create table trade.bigcustomers (cid int not null, cust_name varchar(2000), cust_addr varchar(2000), cust_addr2 varchar(2000)) " +
      " replicate EVICTION BY LRUHEAPPERCENT EVICTACTION overflow synchronous 'teststore' ");
  Connection conn = TestUtil.getConnection();
  CallableStatement cs = conn.prepareCall("call sys.set_eviction_heap_percentage(?)");
  cs.setInt(1, 25);
  cs.execute();
  float evictionHeapPercentage = Misc.getGemFireCache().getResourceManager().getEvictionHeapPercentage();
  TestUtil.getLogger().info("evictionHeapPercentage: "+evictionHeapPercentage);
  PreparedStatement ps = conn.prepareStatement("insert into trade.bigcustomers values(?, ?, ?, ?)");
  
  insertNBigElements(1000, ps, 0);
  VM servervm = this.serverVMs.get(0);
  servervm.invoke(GfxdLRUDUnit.class, "raiseFakeHeapEvictorOnEvent");
  Statement s = conn.createStatement();
  insertNBigElements(1000, ps, 1000);
  
  s.execute("select count(*) from trade.bigcustomers");
  ResultSet rs = s.getResultSet();
  int cnt = 0;
  if (rs.next()) {
    cnt = rs.getInt(1);
  }
  TestUtil.getLogger().info("cnt: "+cnt);
  assertEquals("expected 2000 elements but found " + cnt, 2000, cnt);
}
 
Example 17
Source File: CallableStatementRegressionTest.java    From r-course with MIT License 4 votes vote down vote up
public void testBug43576() throws Exception {
    createTable("TMIX91P",
            "(F01SMALLINT         SMALLINT NOT NULL, F02INTEGER          INTEGER,F03REAL             REAL,"
                    + "F04FLOAT            FLOAT,F05NUMERIC31X4      NUMERIC(31,4), F06NUMERIC16X16     NUMERIC(16,16), F07CHAR_10          CHAR(10),"
                    + " F08VARCHAR_10       VARCHAR(10), F09CHAR_20          CHAR(20), F10VARCHAR_20       VARCHAR(20), F11DATE         DATE,"
                    + " F12DATETIME         DATETIME, PRIMARY KEY (F01SMALLINT))");

    this.stmt.executeUpdate("INSERT INTO TMIX91P VALUES (1,1,1234567.12,1234567.12,111111111111111111111111111.1111,.111111111111111,'1234567890',"
            + "'1234567890','CHAR20CHAR20','VARCHAR20ABCD','2001-01-01','2001-01-01 01:01:01.111')");

    this.stmt.executeUpdate("INSERT INTO TMIX91P VALUES (7,1,1234567.12,1234567.12,22222222222.0001,.99999999999,'1234567896','1234567896','CHAR20',"
            + "'VARCHAR20ABCD','2001-01-01','2001-01-01 01:01:01.111')");

    this.stmt.executeUpdate("INSERT INTO TMIX91P VALUES (12,12,1234567.12,1234567.12,111222333.4444,.1234567890,'2234567891','2234567891','CHAR20',"
            + "'VARCHAR20VARCHAR20','2001-01-01','2001-01-01 01:01:01.111')");

    createProcedure("MSQSPR100",
            "\n( p1_in  INTEGER , p2_in  CHAR(20), OUT p3_out INTEGER, OUT p4_out CHAR(11))\nBEGIN "
                    + "\n SELECT F01SMALLINT,F02INTEGER, F11DATE,F12DATETIME,F03REAL \n FROM TMIX91P WHERE F02INTEGER = p1_in; "
                    + "\n SELECT F02INTEGER,F07CHAR_10,F08VARCHAR_10,F09CHAR_20 \n FROM TMIX91P WHERE  F09CHAR_20 = p2_in ORDER BY F02INTEGER ; "
                    + "\n SET p3_out  = 144; \n SET p4_out  = 'CHARACTER11'; \n SELECT p3_out, p4_out; END");

    String sql = "{call MSQSPR100(1,'CHAR20',?,?)}";

    CallableStatement cs = this.conn.prepareCall(sql);

    cs.registerOutParameter(1, Types.INTEGER);
    cs.registerOutParameter(2, Types.CHAR);

    cs.execute();
    cs.close();

    createProcedure("bug43576_1", "(OUT nfact VARCHAR(100), IN ccuenta VARCHAR(100),\nOUT ffact VARCHAR(100),\nOUT fdoc VARCHAR(100))\nBEGIN"
            + "\nSET nfact = 'ncfact string';\nSET ffact = 'ffact string';\nSET fdoc = 'fdoc string';\nEND");

    createProcedure("bug43576_2", "(IN ccuent1 VARCHAR(100), IN ccuent2 VARCHAR(100),\nOUT nfact VARCHAR(100),\nOUT ffact VARCHAR(100),"
            + "\nOUT fdoc VARCHAR(100))\nBEGIN\nSET nfact = 'ncfact string';\nSET ffact = 'ffact string';\nSET fdoc = 'fdoc string';\nEND");

    Properties props = new Properties();
    props.put("jdbcCompliantTruncation", "true");
    props.put("useInformationSchema", "true");
    Connection conn1 = null;
    conn1 = getConnectionWithProps(props);
    try {
        CallableStatement callSt = conn1.prepareCall("{ call bug43576_1(?, ?, ?, ?) }");
        callSt.setString(2, "xxx");
        callSt.registerOutParameter(1, java.sql.Types.VARCHAR);
        callSt.registerOutParameter(3, java.sql.Types.VARCHAR);
        callSt.registerOutParameter(4, java.sql.Types.VARCHAR);
        callSt.execute();

        assertEquals("ncfact string", callSt.getString(1));
        assertEquals("ffact string", callSt.getString(3));
        assertEquals("fdoc string", callSt.getString(4));

        CallableStatement callSt2 = conn1.prepareCall("{ call bug43576_2(?, ?, ?, ?, ?) }");
        callSt2.setString(1, "xxx");
        callSt2.setString(2, "yyy");
        callSt2.registerOutParameter(3, java.sql.Types.VARCHAR);
        callSt2.registerOutParameter(4, java.sql.Types.VARCHAR);
        callSt2.registerOutParameter(5, java.sql.Types.VARCHAR);
        callSt2.execute();

        assertEquals("ncfact string", callSt2.getString(3));
        assertEquals("ffact string", callSt2.getString(4));
        assertEquals("fdoc string", callSt2.getString(5));

        CallableStatement callSt3 = conn1.prepareCall("{ call bug43576_2(?, 'yyy', ?, ?, ?) }");
        callSt3.setString(1, "xxx");
        // callSt3.setString(2, "yyy");
        callSt3.registerOutParameter(2, java.sql.Types.VARCHAR);
        callSt3.registerOutParameter(3, java.sql.Types.VARCHAR);
        callSt3.registerOutParameter(4, java.sql.Types.VARCHAR);
        callSt3.execute();

        assertEquals("ncfact string", callSt3.getString(2));
        assertEquals("ffact string", callSt3.getString(3));
        assertEquals("fdoc string", callSt3.getString(4));
    } finally {
        conn1.close();
    }
}
 
Example 18
Source File: SQLServerDbWriteAccess.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
/**
 * Insert a new run in the database
 *
 * @param runName
 *            name of the run
 * @param osName
 *            name of the OS
 * @param productName
 *            name of the product
 * @param versionName
 *            version of the product
 * @param buildName
 *            build version
 * @param timestamp
 * @param hostName
 *            name/IP of the machine , from which the run was started
 * @return
 */
public int startRun(
                     String runName,
                     String osName,
                     String productName,
                     String versionName,
                     String buildName,
                     long timestamp,
                     String hostName,
                     boolean closeConnection ) throws DatabaseAccessException {

    timestamp = inUTC(timestamp);

    // then start the run
    final int indexRowsInserted = 8;
    final int indexRunId = 9;

    String errMsg = "Unable to insert run with name " + runName;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_start_run(?, ?, ?, ?, ?, ?, ?, ? ,?) }");
        callableStatement.setString(1, productName);
        callableStatement.setString(2, versionName);
        callableStatement.setString(3, buildName);
        callableStatement.setString(4, runName);
        callableStatement.setString(5, osName);
        callableStatement.setTimestamp(6, new Timestamp(timestamp));
        callableStatement.setString(7, hostName);
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.registerOutParameter(indexRunId, Types.INTEGER);

        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) == 1) {

            // check if the run ID is correct
            if (callableStatement.getInt(indexRunId) == 0) {
                throw new DatabaseAccessException(errMsg
                                                  + " - run ID returned was 0");
            }
        } else {
            throw new DatabaseAccessException(errMsg);
        }

        // get the result
        return callableStatement.getInt(indexRunId);

    } catch (Exception e) {
        String procedureName = "sp_start_run";
        List<Object> argValues = new ArrayList<Object>();
        argValues.add(procedureName);
        argValues.add(versionName);
        argValues.add(buildName);
        argValues.add(runName);
        argValues.add(osName);
        argValues.add(timestamp);
        argValues.add(hostName);

        errMsg += " using the following statement: "
                  + constructStoredProcedureArgumentsMap(procedureName, argValues);
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 19
Source File: LangProcedureTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void sqlControl4(int sqlc, String[] e1, String[] e2,
        String[] e3, String[] e4, String[] e5, String[] e6, String[] e7,
        String[] e8) throws SQLException {

    Connection conn = DriverManager
            .getConnection("jdbc:default:connection");

    String sql = "CALL SQLC.SQLCONTROL2_" + sqlc
            + " (?, ?, ?, ?, ?, ?, ?) ";

    e1[0] = sql;

    CallableStatement cs1 = conn.prepareCall(sql);
    try {
        for (int rop = 1; rop <= 7; rop++) {
            cs1.registerOutParameter(rop, Types.VARCHAR);
        }
        cs1.execute();

        e2[0] = cs1.getString(1);
        e3[0] = cs1.getString(2);
        e4[0] = cs1.getString(3);
        e5[0] = cs1.getString(4);
        e6[0] = cs1.getString(5);
        e7[0] = cs1.getString(6);
        e8[0] = cs1.getString(7);
    } catch (SQLException sqle) {
        StringBuffer sb = new StringBuffer(128);
        sb.append("STATE");
        do {
            sb.append("-");
            String ss = sqle.getSQLState();
            if (ss == null)
                ss = "?????";
            sb.append(ss);
            sqle = sqle.getNextException();
        } while (sqle != null);
        e2[0] = sb.toString();
    }

    cs1.close();

    conn.close();

}
 
Example 20
Source File: SQLServerDbWriteAccess.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
public void endCheckpoint(
                           CheckpointInfo runningCheckpointInfo,
                           long endTimestamp,
                           long transferSize,
                           int result,
                           boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to end checkpoint with name '" + runningCheckpointInfo.getName()
                          + "', checkpoint summary id " + runningCheckpointInfo.getCheckpointSummaryId()
                          + ", id " + runningCheckpointInfo.getCheckpointId();

    endTimestamp = inUTC(endTimestamp);

    final int indexRowsInserted = 8;
    int responseTime = (int) (endTimestamp - runningCheckpointInfo.getStartTimestamp());

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_end_checkpoint(?, ?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, runningCheckpointInfo.getCheckpointSummaryId());
        callableStatement.setLong(2, runningCheckpointInfo.getCheckpointId());
        callableStatement.setInt(3, responseTime >= 0
                                                      ? responseTime
                                                      : 0);
        callableStatement.setLong(4, transferSize);
        callableStatement.setInt(5, result);
        callableStatement.setInt(6, checkpointLogLevel.toInt());
        callableStatement.setTimestamp(7, new Timestamp(endTimestamp));
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);

        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        }
    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}