use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testMixedProcedureNumericPrcisionScaleInorder.
private void testMixedProcedureNumericPrcisionScaleInorder(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.DECIMAL, 18, 0);
callableStatement.registerOutParameter(2, java.sql.Types.DECIMAL, 10, 5);
callableStatement.registerOutParameter(3, java.sql.Types.NUMERIC, 18, 0);
callableStatement.registerOutParameter(4, java.sql.Types.NUMERIC, 8, 2);
callableStatement.setBigDecimal(2, new BigDecimal(numericValues[9]), 10, 5);
callableStatement.setBigDecimal(4, new BigDecimal(numericValues[11]), 8, 2);
callableStatement.execute();
BigDecimal value1 = callableStatement.getBigDecimal(1);
assertEquals(value1, new BigDecimal(numericValues[8]), "Test for input output parameter fails.\n");
BigDecimal value2 = callableStatement.getBigDecimal(2);
assertEquals(value2, new BigDecimal(numericValues[9]), "Test for input output parameter fails.\n");
BigDecimal value3 = callableStatement.getBigDecimal(3);
assertEquals(value3, new BigDecimal(numericValues[10]), "Test for input output parameter fails.\n");
BigDecimal value4 = callableStatement.getBigDecimal(4);
assertEquals(value4, new BigDecimal(numericValues[11]), "Test for input 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 testMixedProcedure.
private void testMixedProcedure(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.setInt(2, Integer.parseInt(numericValues[3]));
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(3, java.sql.Types.DOUBLE);
if (RandomData.returnZero)
callableStatement.setBigDecimal(4, new BigDecimal(numericValues[8]), 18, 0);
else
callableStatement.setBigDecimal(4, new BigDecimal(numericValues[8]));
callableStatement.execute();
int intValue = callableStatement.getInt(2);
assertEquals("" + intValue, numericValues[3], "Test for Inout parameter fails.\n");
double floatValue = callableStatement.getDouble(3);
assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n");
int returnedValue = callableStatement.getInt(1);
assertEquals("" + returnedValue, "" + 123, "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 testMixedProcedureDateScaleInorder.
private void testMixedProcedureDateScaleInorder(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.TIMESTAMP, 2);
callableStatement.registerOutParameter(2, java.sql.Types.TIMESTAMP, 2);
callableStatement.registerOutParameter(3, java.sql.Types.TIME, 2);
callableStatement.registerOutParameter(4, java.sql.Types.TIME, 2);
callableStatement.registerOutParameter(5, microsoft.sql.Types.DATETIMEOFFSET, 2);
callableStatement.registerOutParameter(6, microsoft.sql.Types.DATETIMEOFFSET, 2);
callableStatement.setTimestamp(1, (Timestamp) dateValues.get(4), 2);
callableStatement.setTime(3, (Time) dateValues.get(5), 2);
callableStatement.setDateTimeOffset(5, (DateTimeOffset) dateValues.get(6), 2);
callableStatement.execute();
assertEquals(callableStatement.getTimestamp(1), callableStatement.getTimestamp(2), "Test for output parameter fails.\n");
assertEquals(callableStatement.getTime(3), callableStatement.getTime(4), "Test for output parameter fails.\n");
assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), "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 testMixedProcedure2RandomOrder.
private void testMixedProcedure2RandomOrder(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.FLOAT);
callableStatement.setInt(3, Integer.parseInt(numericValues[3]));
callableStatement.setDouble(4, Double.parseDouble(numericValues[5]));
callableStatement.execute();
double floatValue = callableStatement.getDouble(2);
assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n");
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n");
double floatValue2 = callableStatement.getDouble(2);
assertEquals("" + floatValue2, numericValues[5], "Test for output parameter fails.\n");
int intValue2 = callableStatement.getInt(1);
assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n");
int intValue3 = callableStatement.getInt(1);
assertEquals("" + intValue3, numericValues[3], "Test for output parameter fails.\n");
double floatValue3 = callableStatement.getDouble(2);
assertEquals("" + floatValue3, numericValues[5], "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 getStringGUIDTest.
/**
* Tests CallableStatement.getString() with uniqueidentifier parameter
*
* @throws SQLException
*/
@Test
public void getStringGUIDTest() throws SQLException {
String sql = "{call " + outputProcedureNameGUID + "(?)}";
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) connection.prepareCall(sql)) {
UUID originalValue = UUID.randomUUID();
callableStatement.registerOutParameter(1, microsoft.sql.Types.GUID);
callableStatement.setObject(1, originalValue.toString(), microsoft.sql.Types.GUID);
callableStatement.execute();
String retrievedValue = callableStatement.getString(1);
assertEquals(originalValue.toString().toLowerCase(), retrievedValue.toLowerCase());
}
}
Aggregations