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

The following examples show how to use java.sql.CallableStatement#setShort() . These examples are extracted from open source projects. 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
@Test
public void testBatch() throws SQLException, MalformedURLException {
    CallableStatement preparedStatement = multiHostConnection.prepareCall("UPDATE test SET a = ? WHERE b = ?");
    preparedStatement.setShort(1, (short) 12);
    preparedStatement.setTime(2, new Time(System.currentTimeMillis()));
    preparedStatement.addBatch();
    int[] resultSet = preparedStatement.executeBatch();
    preparedStatement.clearBatch();

    verify(mysqlCallableStatement).executeBatch();
    verify(mysqlCallableStatement).addBatch();
    verify(mysqlCallableStatement).clearBatch();

    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/CallableStatement/executeBatch", "");
}
 
Example 2
static synchronized void compress(Connection conn)
throws java.lang.Exception {
	System.out.println("compressing table");
	try {
		conn.setAutoCommit(true);
		CallableStatement cs = conn
			.prepareCall("CALL SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE(?, ?, ?, ?, ?)");
		cs.setString(1, "SPLICE");
		cs.setString(2, "DATATYPES");
		cs.setShort(3, (short) 1);
		cs.setShort(4, (short) 1);
		cs.setShort(5, (short) 1);
		cs.execute();
		cs.close();
	} catch (SQLException se) {
		System.out.println("compress table: FAIL -- unexpected exception:");
		JDBCDisplayUtil.ShowException(System.out, se);
	}
}
 
Example 3
static synchronized void compress(Connection conn)
throws java.lang.Exception {
	System.out.println("compressing table");
	boolean autocom = conn.getAutoCommit();
	try {
		conn.setAutoCommit(true);
		CallableStatement cs = conn.prepareCall(
			"CALL SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE(?, ?, ?, ?, ?)");
		cs.setString(1, "SPLICE");
		cs.setString(2, "DATATYPES");
		cs.setShort(3, (short) 1);
		cs.setShort(4, (short) 1);
		cs.setShort(5, (short) 1);
		cs.execute();
		cs.close();
	} catch (SQLException se) {
		System.out.println("compress table: FAIL -- unexpected exception:");
		JDBCDisplayUtil.ShowException(System.out, se);
		se.printStackTrace();
	}
	conn.setAutoCommit(autocom);
}
 
Example 4
Source Project: gemfirexd-oss   File: CallableTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Calls a SQL procedure that takes numeric IN and OUT parameters.
 * Excluded from JSR169/j2ME, which doesn't support get/set BigDecimal yet.
 * @throws SQLException 
 */
public void xtestNumericTypesInAndOutProc() throws SQLException
{
    CallableStatement cs = prepareCall
        ("call NUMERIC_TYPES_IN_AND_OUT_PROC(?,?,?,?,?,?,?,?,?,?,?,?)");

    cs.setShort(1, (short) 3);
    cs.setInt(2, 4);
    cs.setLong(3, 5);
    cs.setFloat(4, (float) 6.0);
    cs.setDouble(5, 7.0);
    cs.setBigDecimal(6, new BigDecimal("88.88"));

    cs.registerOutParameter (7, java.sql.Types.SMALLINT);
    cs.registerOutParameter (8, java.sql.Types.INTEGER);
    cs.registerOutParameter (9, java.sql.Types.BIGINT);
    cs.registerOutParameter (10, java.sql.Types.REAL);
    cs.registerOutParameter (11, java.sql.Types.DOUBLE);
    cs.registerOutParameter (12, java.sql.Types.DECIMAL);

    cs.execute();

    assertEquals("OUT short", (short) 3, cs.getShort(7));
    assertEquals("OUT int"  , 4, cs.getInt(8));
    assertEquals("OUT long" , 5, cs.getLong(9));
    assertEquals("OUT float" , (float) 6.0, cs.getFloat(10), .0001);
    assertEquals("OUT double" , 7.0, cs.getDouble(11), .0001);
    assertDecimalSameValue("OUT decimal", "88.88", cs.getBigDecimal(12));
}
 
Example 5
Source Project: gemfirexd-oss   File: CallableTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Calls a SQL procedure that takes INOUT parameters of various types.
 * @throws SQLException 
 */
public void testManyTypesInoutProc() throws SQLException
{
    CallableStatement cs = prepareCall
        ("call MANY_TYPES_INOUT_PROC(?,?,?,?,?,?,?,?,?,?,?,?)");

    cs.registerOutParameter (2, java.sql.Types.SMALLINT);
    cs.registerOutParameter (4, java.sql.Types.INTEGER);
    cs.registerOutParameter (6, java.sql.Types.BIGINT);
    cs.registerOutParameter (8, java.sql.Types.REAL);
    cs.registerOutParameter (10, java.sql.Types.DOUBLE);
    cs.registerOutParameter (12, java.sql.Types.TIME);

    cs.setShort(1, (short)6);
    cs.setShort(2, (short)9);
    cs.setInt(3, 6);
    cs.setInt(4, 9);
    cs.setLong(5, (long)99999);
    cs.setLong(6, (long)88888888);
    cs.setFloat(7, (float)6.123453);
    cs.setFloat(8, (float)77777);
    cs.setDouble(9, (double)6.123453);
    cs.setDouble(10, (double)8888888888888.01234);
    cs.setTime(11, Time.valueOf("11:06:03"));
    cs.setTime(12, Time.valueOf("10:05:02"));

    cs.execute();

    assertEquals("Short: Sum of 6 + 9", 15, cs.getShort(2));
    assertEquals("Int: Sum of 6 + 9", 15, cs.getInt(4));
    assertEquals("Long: Sum of 99999 + 88888888", 88988887, cs.getLong(6));
    assertEquals("Float: Sum of 6.123453 and 77777" , (float) 77783.123453,
        cs.getFloat(8), .000001);
    assertEquals("Double: Sum of Sum of 6.987654 and 8888888888888.01234",
        8.888888888894135e12, cs.getDouble(10), .000001);
    assertEquals("Time: changed to", Time.valueOf("11:06:03"), 
        cs.getTime(12));

}
 
Example 6
Source Project: gemfirexd-oss   File: DbTasks.java    License: Apache License 2.0 5 votes vote down vote up
public void compressTable(Connection conn, String tabname,
		String thread_name)
// preiodically compresses the table to get back the free spaces available
// after
// the deletion of some rows
{
	long s_compress = System.currentTimeMillis();
	long dbsize = databaseSize("mailsdb/seg0");
	MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
			+ "dbsize before compress : " + dbsize);
	try {
		boolean saveAutoCommit = conn.getAutoCommit();
		conn.setAutoCommit(true);
		CallableStatement cs = conn
				.prepareCall("CALL SYSCS_UTIL.INPLACE_COMPRESS_TABLE(?, ?, ?, ?, ?)");
		cs.setString(1, "REFRESH");
		cs.setString(2, tabname);
		cs.setShort(3, (short) 1);
		cs.setShort(4, (short) 1);
		cs.setShort(5, (short) 1);
		cs.execute();
		conn.setAutoCommit(saveAutoCommit);
		cs.close();
	} catch (Throwable sqe) {
		MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
				+ "Error while doing the Compress procedure: "
				+ sqe.getMessage());
		sqe.printStackTrace();
		errorPrint(sqe);
	}
	long e_compress = System.currentTimeMillis();
	MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
			+ "Finished Compressing the table: " + tabname);
	log.logMsg(LogFile.INFO + thread_name + " : "
			+ "Time taken to compress the table : " + tabname
			+ PerfTime.readableTime(e_compress - s_compress));
	dbsize = databaseSize("mailsdb/seg0");
	MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
			+ "dbsize after compress : " + dbsize);
}
 
Example 7
Source Project: gemfirexd-oss   File: CallableTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Calls a SQL procedure that takes numeric IN and OUT parameters.
 * Excluded from JSR169/j2ME, which doesn't support get/set BigDecimal yet.
 * @throws SQLException 
 */
public void xtestNumericTypesInAndOutProc() throws SQLException
{
    CallableStatement cs = prepareCall
        ("call NUMERIC_TYPES_IN_AND_OUT_PROC(?,?,?,?,?,?,?,?,?,?,?,?)");

    cs.setShort(1, (short) 3);
    cs.setInt(2, 4);
    cs.setLong(3, 5);
    cs.setFloat(4, (float) 6.0);
    cs.setDouble(5, 7.0);
    cs.setBigDecimal(6, new BigDecimal("88.88"));

    cs.registerOutParameter (7, java.sql.Types.SMALLINT);
    cs.registerOutParameter (8, java.sql.Types.INTEGER);
    cs.registerOutParameter (9, java.sql.Types.BIGINT);
    cs.registerOutParameter (10, java.sql.Types.REAL);
    cs.registerOutParameter (11, java.sql.Types.DOUBLE);
    cs.registerOutParameter (12, java.sql.Types.DECIMAL);

    cs.execute();

    assertEquals("OUT short", (short) 3, cs.getShort(7));
    assertEquals("OUT int"  , 4, cs.getInt(8));
    assertEquals("OUT long" , 5, cs.getLong(9));
    assertEquals("OUT float" , (float) 6.0, cs.getFloat(10), .0001);
    assertEquals("OUT double" , 7.0, cs.getDouble(11), .0001);
    assertDecimalSameValue("OUT decimal", "88.88", cs.getBigDecimal(12));
}
 
Example 8
Source Project: gemfirexd-oss   File: CallableTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Calls a SQL procedure that takes INOUT parameters of various types.
 * @throws SQLException 
 */
public void testManyTypesInoutProc() throws SQLException
{
    CallableStatement cs = prepareCall
        ("call MANY_TYPES_INOUT_PROC(?,?,?,?,?,?,?,?,?,?,?,?)");

    cs.registerOutParameter (2, java.sql.Types.SMALLINT);
    cs.registerOutParameter (4, java.sql.Types.INTEGER);
    cs.registerOutParameter (6, java.sql.Types.BIGINT);
    cs.registerOutParameter (8, java.sql.Types.REAL);
    cs.registerOutParameter (10, java.sql.Types.DOUBLE);
    cs.registerOutParameter (12, java.sql.Types.TIME);

    cs.setShort(1, (short)6);
    cs.setShort(2, (short)9);
    cs.setInt(3, 6);
    cs.setInt(4, 9);
    cs.setLong(5, (long)99999);
    cs.setLong(6, (long)88888888);
    cs.setFloat(7, (float)6.123453);
    cs.setFloat(8, (float)77777);
    cs.setDouble(9, (double)6.123453);
    cs.setDouble(10, (double)8888888888888.01234);
    cs.setTime(11, Time.valueOf("11:06:03"));
    cs.setTime(12, Time.valueOf("10:05:02"));

    cs.execute();

    assertEquals("Short: Sum of 6 + 9", 15, cs.getShort(2));
    assertEquals("Int: Sum of 6 + 9", 15, cs.getInt(4));
    assertEquals("Long: Sum of 99999 + 88888888", 88988887, cs.getLong(6));
    assertEquals("Float: Sum of 6.123453 and 77777" , (float) 77783.123453,
        cs.getFloat(8), .000001);
    assertEquals("Double: Sum of Sum of 6.987654 and 8888888888888.01234",
        8.888888888894135e12, cs.getDouble(10), .000001);
    assertEquals("Time: changed to", Time.valueOf("11:06:03"), 
        cs.getTime(12));

}
 
Example 9
Source Project: gemfirexd-oss   File: DbTasks.java    License: Apache License 2.0 5 votes vote down vote up
public void compressTable(Connection conn, String tabname,
		String thread_name)
// preiodically compresses the table to get back the free spaces available
// after
// the deletion of some rows
{
	long s_compress = System.currentTimeMillis();
	long dbsize = databaseSize("mailsdb/seg0");
	MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
			+ "dbsize before compress : " + dbsize);
	try {
		boolean saveAutoCommit = conn.getAutoCommit();
		conn.setAutoCommit(true);
		CallableStatement cs = conn
				.prepareCall("CALL SYSCS_UTIL.INPLACE_COMPRESS_TABLE(?, ?, ?, ?, ?)");
		cs.setString(1, "REFRESH");
		cs.setString(2, tabname);
		cs.setShort(3, (short) 1);
		cs.setShort(4, (short) 1);
		cs.setShort(5, (short) 1);
		cs.execute();
		conn.setAutoCommit(saveAutoCommit);
		cs.close();
	} catch (Throwable sqe) {
		MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
				+ "Error while doing the Compress procedure: "
				+ sqe.getMessage());
		sqe.printStackTrace();
		errorPrint(sqe);
	}
	long e_compress = System.currentTimeMillis();
	MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
			+ "Finished Compressing the table: " + tabname);
	log.logMsg(LogFile.INFO + thread_name + " : "
			+ "Time taken to compress the table : " + tabname
			+ PerfTime.readableTime(e_compress - s_compress));
	dbsize = databaseSize("mailsdb/seg0");
	MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
			+ "dbsize after compress : " + dbsize);
}
 
Example 10
/**
 * Calls a SQL procedure that takes numeric IN and OUT parameters.
 * Excluded from JSR169/j2ME, which doesn't support get/set BigDecimal yet.
 * @throws SQLException 
 */
public void xtestNumericTypesInAndOutProc() throws SQLException
{
    CallableStatement cs = prepareCall
        ("call NUMERIC_TYPES_IN_AND_OUT_PROC(?,?,?,?,?,?,?,?,?,?,?,?)");

    cs.setShort(1, (short) 3);
    cs.setInt(2, 4);
    cs.setLong(3, 5);
    cs.setFloat(4, (float) 6.0);
    cs.setDouble(5, 7.0);
    cs.setBigDecimal(6, new BigDecimal("88.88"));

    cs.registerOutParameter (7, java.sql.Types.SMALLINT);
    cs.registerOutParameter (8, java.sql.Types.INTEGER);
    cs.registerOutParameter (9, java.sql.Types.BIGINT);
    cs.registerOutParameter (10, java.sql.Types.REAL);
    cs.registerOutParameter (11, java.sql.Types.DOUBLE);
    cs.registerOutParameter (12, java.sql.Types.DECIMAL);

    cs.execute();

    assertEquals("OUT short", (short) 3, cs.getShort(7));
    assertEquals("OUT int"  , 4, cs.getInt(8));
    assertEquals("OUT long" , 5, cs.getLong(9));
    assertEquals("OUT float" , (float) 6.0, cs.getFloat(10), .0001);
    assertEquals("OUT double" , 7.0, cs.getDouble(11), .0001);
    assertDecimalSameValue("OUT decimal", "88.88", cs.getBigDecimal(12));

    // test that setObject() does the right thing for BigDecimal. see db-5488.
    cs.setObject(3, new BigDecimal( "10" ) );
    cs.execute();
    assertEquals("OUT long" , 10, cs.getLong(9));

    // test that setObject() does the right thing for BigInteger. see db-5488.
    cs.setObject(3, new BigInteger( "11" ) );
    cs.execute();
    assertEquals("OUT long" , 11, cs.getLong(9));
}
 
Example 11
/**
 * Calls a SQL procedure that takes INOUT parameters of various types.
 * @throws SQLException 
 */
public void testManyTypesInoutProc() throws SQLException
{
    CallableStatement cs = prepareCall
        ("call MANY_TYPES_INOUT_PROC(?,?,?,?,?,?,?,?,?,?,?,?)");

    cs.registerOutParameter (2, java.sql.Types.SMALLINT);
    cs.registerOutParameter (4, java.sql.Types.INTEGER);
    cs.registerOutParameter (6, java.sql.Types.BIGINT);
    cs.registerOutParameter (8, java.sql.Types.REAL);
    cs.registerOutParameter (10, java.sql.Types.DOUBLE);
    cs.registerOutParameter (12, java.sql.Types.TIME);

    cs.setShort(1, (short)6);
    cs.setShort(2, (short)9);
    cs.setInt(3, 6);
    cs.setInt(4, 9);
    cs.setLong(5, (long)99999);
    cs.setLong(6, (long)88888888);
    cs.setFloat(7, (float)6.123453);
    cs.setFloat(8, (float)77777);
    cs.setDouble(9, (double)6.123453);
    cs.setDouble(10, (double)8888888888888.01234);
    cs.setTime(11, Time.valueOf("11:06:03"));
    cs.setTime(12, Time.valueOf("10:05:02"));

    cs.execute();

    assertEquals("Short: Sum of 6 + 9", 15, cs.getShort(2));
    assertEquals("Int: Sum of 6 + 9", 15, cs.getInt(4));
    assertEquals("Long: Sum of 99999 + 88888888", 88988887, cs.getLong(6));
    assertEquals("Float: Sum of 6.123453 and 77777" , (float) 77783.123453,
        cs.getFloat(8), .000001);
    assertEquals("Double: Sum of Sum of 6.987654 and 8888888888888.01234",
        8.888888888894135e12, cs.getDouble(10), .000001);
    assertEquals("Time: changed to", Time.valueOf("11:06:03"), 
        cs.getTime(12));

}
 
Example 12
private void reduceSizeOnDisk(Connection conn)
{
    CallableStatement cs = null;
    PreparedStatement stmt = null;
    try
    {
        String tableQuery =
                "SELECT S.SCHEMANAME, T.TABLENAME FROM SYS.SYSSCHEMAS S, SYS.SYSTABLES T WHERE S.SCHEMAID = T.SCHEMAID AND T.TABLETYPE='T'";
        stmt = conn.prepareStatement(tableQuery);
        ResultSet rs = null;

        List<String> schemas = new ArrayList<String>();
        List<String> tables = new ArrayList<String>();

        try
        {
            rs = stmt.executeQuery();
            while(rs.next())
            {
                schemas.add(rs.getString(1));
                tables.add(rs.getString(2));
            }
        }
        finally
        {
            if(rs != null)
            {
                rs.close();
            }
        }


        cs = conn.prepareCall
                ("CALL SYSCS_UTIL.SYSCS_COMPRESS_TABLE(?, ?, ?)");

        for(int i = 0; i < schemas.size(); i++)
        {
            cs.setString(1, schemas.get(i));
            cs.setString(2, tables.get(i));
            cs.setShort(3, (short) 0);
            cs.execute();
        }
    }
    catch (SQLException e)
    {
        throw new StoreException("Error reducing on disk size", e);
    }
    finally
    {
        JdbcUtils.closePreparedStatement(stmt, getLogger());
        JdbcUtils.closePreparedStatement(cs, getLogger());
    }
}