use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testOutputProcedureBinaryInorder.
private void testOutputProcedureBinaryInorder(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.BINARY, 20, 0);
callableStatement.registerOutParameter(2, java.sql.Types.VARBINARY, 50, 0);
callableStatement.registerOutParameter(3, java.sql.Types.LONGVARBINARY);
callableStatement.registerOutParameter(4, java.sql.Types.BINARY, 512, 0);
callableStatement.registerOutParameter(5, java.sql.Types.VARBINARY, 8000, 0);
callableStatement.execute();
byte[] expected = byteValues.get(0);
byte[] received1 = callableStatement.getBytes(1);
for (int i = 0; i < expected.length; i++) {
assertEquals(received1[i], expected[i], "Test for output parameter fails.\n");
}
expected = byteValues.get(1);
byte[] received2 = callableStatement.getBytes(2);
for (int i = 0; i < expected.length; i++) {
assertEquals(received2[i], expected[i], "Test for output parameter fails.\n");
}
expected = byteValues.get(2);
byte[] received3 = callableStatement.getBytes(3);
for (int i = 0; i < expected.length; i++) {
assertEquals(received3[i], expected[i], "Test for output parameter fails.\n");
}
expected = byteValues.get(3);
byte[] received4 = callableStatement.getBytes(4);
for (int i = 0; i < expected.length; i++) {
assertEquals(received4[i], expected[i], "Test for output parameter fails.\n");
}
expected = byteValues.get(4);
byte[] received5 = callableStatement.getBytes(5);
for (int i = 0; i < expected.length; i++) {
assertEquals(received5[i], expected[i], "Test for output parameter fails.\n");
}
} catch (Exception e) {
fail(e.toString());
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testInOutProcedure.
private void testInOutProcedure(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.setInt(1, Integer.parseInt(numericValues[3]));
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.execute();
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, numericValues[3], "Test for Inout parameter fails.\n");
} catch (Exception e) {
fail(e.toString());
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testInputProcedure2.
private void testInputProcedure2(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.setString(1, charValues[1]);
callableStatement.setUniqueIdentifier(2, charValues[6]);
callableStatement.setString(3, charValues[2]);
callableStatement.setNString(4, charValues[3]);
callableStatement.setNString(5, charValues[4]);
callableStatement.setNString(6, charValues[5]);
callableStatement.setString(7, charValues[7]);
callableStatement.setNString(8, charValues[8]);
try (SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery()) {
rs.next();
assertEquals(rs.getString(1).trim(), charValues[1], "Test for input parameter fails.\n");
assertEquals(rs.getUniqueIdentifier(2), charValues[6].toUpperCase(), "Test for input parameter fails.\n");
assertEquals(rs.getString(3).trim(), charValues[2], "Test for input parameter fails.\n");
assertEquals(rs.getString(4).trim(), charValues[3], "Test for input parameter fails.\n");
assertEquals(rs.getString(5).trim(), charValues[4], "Test for input parameter fails.\n");
assertEquals(rs.getString(6).trim(), charValues[5], "Test for input parameter fails.\n");
assertEquals(rs.getString(7).trim(), charValues[7], "Test for input parameter fails.\n");
assertEquals(rs.getString(8).trim(), charValues[8], "Test for input parameter fails.\n");
}
} catch (Exception e) {
fail(e.toString());
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testOutputProcedureRandomOrder.
private void testOutputProcedureRandomOrder(String sql, String[] values) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.DOUBLE);
callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(4, java.sql.Types.BIGINT);
callableStatement.registerOutParameter(5, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(6, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(7, microsoft.sql.Types.MONEY);
callableStatement.execute();
double floatValue0 = callableStatement.getDouble(2);
assertEquals("" + floatValue0, "" + values[5], "Test for output parameter fails.\n");
long bigintValue = callableStatement.getLong(4);
assertEquals("" + bigintValue, values[4], "Test for output parameter fails.\n");
// tinyint
short tinyintValue = callableStatement.getShort(5);
assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n");
double floatValue1 = callableStatement.getDouble(2);
assertEquals("" + floatValue1, "" + values[5], "Test for output parameter fails.\n");
int intValue2 = callableStatement.getInt(1);
assertEquals("" + intValue2, "" + values[3], "Test for output parameter fails.\n");
double floatValue2 = callableStatement.getDouble(2);
assertEquals("" + floatValue2, "" + values[5], "Test for output parameter fails.\n");
// smallint
short shortValue3 = callableStatement.getShort(3);
assertEquals("" + shortValue3, "" + values[2], "Test for output parameter fails.\n");
short shortValue32 = callableStatement.getShort(3);
assertEquals("" + shortValue32, "" + values[2], "Test for output parameter fails.\n");
BigDecimal smallmoney1 = callableStatement.getSmallMoney(6);
assertEquals("" + smallmoney1, "" + values[12], "Test for output parameter fails.\n");
BigDecimal money1 = callableStatement.getMoney(7);
assertEquals("" + money1, "" + values[13], "Test for output parameter fails.\n");
} catch (Exception e) {
fail(e.toString());
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testOutputProcedureBinaryInorderObject.
private void testOutputProcedureBinaryInorderObject(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.BINARY, 20, 0);
callableStatement.registerOutParameter(2, java.sql.Types.VARBINARY, 50, 0);
callableStatement.registerOutParameter(3, java.sql.Types.LONGVARBINARY);
callableStatement.registerOutParameter(4, java.sql.Types.BINARY, 512, 0);
callableStatement.registerOutParameter(5, java.sql.Types.VARBINARY, 8000, 0);
callableStatement.execute();
int index = 1;
for (int i = 0; i < byteValues.size(); i++) {
byte[] expected = null;
if (null != byteValues.get(i))
expected = byteValues.get(i);
byte[] binaryValue = (byte[]) callableStatement.getObject(index);
try {
if (null != byteValues.get(i)) {
for (int j = 0; j < expected.length; j++) {
assertEquals(expected[j] == binaryValue[j] && expected[j] == binaryValue[j] && expected[j] == binaryValue[j], true, "Decryption failed with getObject(): " + binaryValue + ", " + binaryValue + ", " + binaryValue + ".\n");
}
}
} catch (Exception e) {
fail(e.toString());
} finally {
index++;
}
}
} catch (Exception e) {
fail(e.toString());
}
}
Aggregations