use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testOutputProcedureReverseOrder.
private void testOutputProcedureReverseOrder(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();
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");
short tinyintValue = callableStatement.getShort(5);
assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n");
long bigintValue = callableStatement.getLong(4);
assertEquals("" + bigintValue, values[4], "Test for output parameter fails.\n");
short shortValue3 = callableStatement.getShort(3);
assertEquals("" + shortValue3, values[2], "Test for output parameter fails.\n");
double floatValue0 = callableStatement.getDouble(2);
assertEquals("" + floatValue0, values[5], "Test for output parameter fails.\n");
int intValue2 = callableStatement.getInt(1);
assertEquals("" + intValue2, values[3], "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 testOutputProcedure3RandomOrder.
private void testOutputProcedure3RandomOrder(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.INTEGER);
callableStatement.execute();
int intValue2 = callableStatement.getInt(2);
assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n");
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n");
int intValue3 = callableStatement.getInt(2);
assertEquals("" + intValue3, numericValues[3], "Test for output parameter fails.\n");
int intValue4 = callableStatement.getInt(2);
assertEquals("" + intValue4, numericValues[3], "Test for output parameter fails.\n");
int intValue5 = callableStatement.getInt(1);
assertEquals("" + intValue5, numericValues[3], "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 testOutputProcedureNumericInorder.
private void testOutputProcedureNumericInorder(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.BIT);
callableStatement.registerOutParameter(2, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(4, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(5, java.sql.Types.BIGINT);
callableStatement.registerOutParameter(6, java.sql.Types.DOUBLE);
callableStatement.registerOutParameter(7, java.sql.Types.DOUBLE, 30, 0);
callableStatement.registerOutParameter(8, java.sql.Types.REAL);
callableStatement.registerOutParameter(9, java.sql.Types.DECIMAL, 18, 0);
callableStatement.registerOutParameter(10, java.sql.Types.DECIMAL, 10, 5);
callableStatement.registerOutParameter(11, java.sql.Types.NUMERIC, 18, 0);
callableStatement.registerOutParameter(12, java.sql.Types.NUMERIC, 8, 2);
callableStatement.registerOutParameter(13, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(14, microsoft.sql.Types.MONEY);
callableStatement.registerOutParameter(15, java.sql.Types.DECIMAL, 28, 4);
callableStatement.registerOutParameter(16, java.sql.Types.NUMERIC, 28, 4);
callableStatement.execute();
int bitValue = callableStatement.getInt(1);
if (bitValue == 0)
assertEquals("" + false, numericValues[0], "Test for output parameter fails.\n");
else
assertEquals("" + true, numericValues[0], "Test for output parameter fails.\n");
short tinyIntValue = callableStatement.getShort(2);
assertEquals("" + tinyIntValue, numericValues[1], "Test for output parameter fails.\n");
short smallIntValue = callableStatement.getShort(3);
assertEquals("" + smallIntValue, numericValues[2], "Test for output parameter fails.\n");
int intValue = callableStatement.getInt(4);
assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n");
long bigintValue = callableStatement.getLong(5);
assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n");
double floatDefault = callableStatement.getDouble(6);
assertEquals("" + floatDefault, numericValues[5], "Test for output parameter fails.\n");
double floatValue = callableStatement.getDouble(7);
assertEquals("" + floatValue, numericValues[6], "Test for output parameter fails.\n");
float realValue = callableStatement.getFloat(8);
assertEquals("" + realValue, numericValues[7], "Test for output parameter fails.\n");
BigDecimal decimalDefault = callableStatement.getBigDecimal(9);
assertEquals(decimalDefault, new BigDecimal(numericValues[8]), "Test for output parameter fails.\n");
BigDecimal decimalValue = callableStatement.getBigDecimal(10);
assertEquals(decimalValue, new BigDecimal(numericValues[9]), "Test for output parameter fails.\n");
BigDecimal numericDefault = callableStatement.getBigDecimal(11);
assertEquals(numericDefault, new BigDecimal(numericValues[10]), "Test for output parameter fails.\n");
BigDecimal numericValue = callableStatement.getBigDecimal(12);
assertEquals(numericValue, new BigDecimal(numericValues[11]), "Test for output parameter fails.\n");
BigDecimal smallMoneyValue = callableStatement.getSmallMoney(13);
assertEquals(smallMoneyValue, new BigDecimal(numericValues[12]), "Test for output parameter fails.\n");
BigDecimal moneyValue = callableStatement.getMoney(14);
assertEquals(moneyValue, new BigDecimal(numericValues[13]), "Test for output parameter fails.\n");
BigDecimal decimalValue2 = callableStatement.getBigDecimal(15);
assertEquals(decimalValue2, new BigDecimal(numericValues[14]), "Test for output parameter fails.\n");
BigDecimal numericValue2 = callableStatement.getBigDecimal(16);
assertEquals(numericValue2, new BigDecimal(numericValues[15]), "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 testOutputProcedureCharInorderObject.
private void testOutputProcedureCharInorderObject(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.CHAR, 20, 0);
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR, 50, 0);
callableStatement.registerOutParameter(3, java.sql.Types.NCHAR, 30, 0);
callableStatement.registerOutParameter(4, java.sql.Types.NVARCHAR, 60, 0);
callableStatement.registerOutParameter(5, microsoft.sql.Types.GUID);
callableStatement.registerOutParameter(6, java.sql.Types.LONGVARCHAR);
callableStatement.registerOutParameter(7, java.sql.Types.LONGNVARCHAR);
callableStatement.registerOutParameter(8, java.sql.Types.VARCHAR, 8000, 0);
callableStatement.registerOutParameter(9, java.sql.Types.NVARCHAR, 4000, 0);
callableStatement.execute();
String charValue = (String) callableStatement.getObject(1);
assertEquals(charValue.trim(), charValues[0], "Test for output parameter fails.\n");
String varcharValue = (String) callableStatement.getObject(2);
assertEquals(varcharValue.trim(), charValues[1], "Test for output parameter fails.\n");
String ncharValue = (String) callableStatement.getObject(3);
assertEquals(ncharValue.trim(), charValues[3], "Test for output parameter fails.\n");
String nvarcharValue = (String) callableStatement.getObject(4);
assertEquals(nvarcharValue.trim(), charValues[4], "Test for output parameter fails.\n");
String uniqueIdentifierValue = (String) callableStatement.getObject(5);
assertEquals(uniqueIdentifierValue.toLowerCase(), charValues[6], "Test for output parameter fails.\n");
String varcharValuemax = (String) callableStatement.getObject(6);
assertEquals(varcharValuemax, charValues[2], "Test for output parameter fails.\n");
String nvarcharValuemax = (String) callableStatement.getObject(7);
assertEquals(nvarcharValuemax.trim(), charValues[5], "Test for output parameter fails.\n");
String varcharValue8000 = (String) callableStatement.getObject(8);
assertEquals(varcharValue8000, charValues[7], "Test for output parameter fails.\n");
String nvarcharValue4000 = (String) callableStatement.getObject(9);
assertEquals(nvarcharValue4000, charValues[8], "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 testOutputProcedureDateInorder.
private void testOutputProcedureDateInorder(String sql) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.DATE);
callableStatement.registerOutParameter(2, java.sql.Types.DATE);
callableStatement.registerOutParameter(3, java.sql.Types.TIMESTAMP);
callableStatement.registerOutParameter(4, java.sql.Types.TIMESTAMP);
callableStatement.registerOutParameter(5, microsoft.sql.Types.DATETIMEOFFSET);
callableStatement.registerOutParameter(6, microsoft.sql.Types.DATETIMEOFFSET);
callableStatement.registerOutParameter(7, java.sql.Types.TIME);
callableStatement.registerOutParameter(8, java.sql.Types.TIME);
// datetime
callableStatement.registerOutParameter(9, microsoft.sql.Types.DATETIME);
// datetime
callableStatement.registerOutParameter(10, microsoft.sql.Types.DATETIME);
// smalldatetime
callableStatement.registerOutParameter(11, microsoft.sql.Types.SMALLDATETIME);
// smalldatetime
callableStatement.registerOutParameter(12, microsoft.sql.Types.SMALLDATETIME);
callableStatement.registerOutParameter(13, java.sql.Types.TIMESTAMP, 2);
callableStatement.registerOutParameter(14, java.sql.Types.TIMESTAMP, 2);
callableStatement.registerOutParameter(15, java.sql.Types.TIME, 2);
callableStatement.registerOutParameter(16, java.sql.Types.TIME, 2);
callableStatement.registerOutParameter(17, microsoft.sql.Types.DATETIMEOFFSET, 2);
callableStatement.registerOutParameter(18, microsoft.sql.Types.DATETIMEOFFSET, 2);
callableStatement.execute();
assertEquals(callableStatement.getDate(1), callableStatement.getDate(2), "Test for output parameter fails.\n");
assertEquals(callableStatement.getTimestamp(3), callableStatement.getTimestamp(4), "Test for output parameter fails.\n");
assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), "Test for output parameter fails.\n");
assertEquals(callableStatement.getTime(7), callableStatement.getTime(8), "Test for output parameter fails.\n");
assertEquals(// actual plain
callableStatement.getDateTime(9), // received expected enc
callableStatement.getDateTime(10), "Test for output parameter fails.\n");
assertEquals(callableStatement.getSmallDateTime(11), callableStatement.getSmallDateTime(12), "Test for output parameter fails.\n");
assertEquals(callableStatement.getTimestamp(13), callableStatement.getTimestamp(14), "Test for output parameter fails.\n");
assertEquals(callableStatement.getTime(15).getTime(), callableStatement.getTime(16).getTime(), "Test for output parameter fails.\n");
assertEquals(callableStatement.getDateTimeOffset(17), callableStatement.getDateTimeOffset(18), "Test for output parameter fails.\n");
} catch (Exception e) {
fail(e.toString());
}
}
Aggregations