use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testOutputProcedure3Inorder.
private void testOutputProcedure3Inorder(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 intValue = callableStatement.getInt(1);
assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n");
int intValue2 = callableStatement.getInt(2);
assertEquals("" + intValue2, 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 testMixedProcedure2Inorder.
private void testMixedProcedure2Inorder(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();
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n");
double floatValue = callableStatement.getDouble(2);
assertEquals("" + floatValue, 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 TVPWithSqlVariantTest method testIntStoredProcedure.
/**
* Test with stored procedure
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testIntStoredProcedure() throws SQLException {
java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf("2007-09-23 10:10:10.0");
final String sql = "{call " + procedureName + "(?)}";
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
tvp.addRow(timestamp);
SQLServerCallableStatement Cstatement = (SQLServerCallableStatement) connection.prepareCall(sql);
Cstatement.setStructured(1, tvpName, tvp);
Cstatement.execute();
rs = (SQLServerResultSet) stmt.executeQuery("select * from " + destTable);
while (rs.next()) {
System.out.println(rs.getString(1));
}
if (null != Cstatement) {
Cstatement.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class WrapperTest method wrapTest.
/**
* Wrapper tests
* @throws Exception
*/
@Test
public void wrapTest() throws Exception {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(connectionString);
Statement stmt = con.createStatement();
try {
// First make sure that a statement can be unwrapped
boolean isWrapper = ((SQLServerStatement) stmt).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerStatement"));
assertEquals(isWrapper, true, "SQLServerStatement should be a wrapper for self");
isWrapper = ((SQLServerStatement) stmt).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerStatement"));
assertEquals(isWrapper, true, "SQLServerStatement should be a wrapper for ISQLServerStatement");
isWrapper = ((SQLServerStatement) stmt).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerConnection"));
assertEquals(isWrapper, false, "SQLServerStatement should not be a wrapper for SQLServerConnection");
// Now make sure that we can unwrap a SQLServerCallableStatement to a SQLServerStatement
CallableStatement cs = con.prepareCall("{ ? = CALL " + "ProcName" + " (?, ?, ?, ?) }");
// Test the class first
isWrapper = ((SQLServerCallableStatement) cs).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerStatement"));
assertEquals(isWrapper, true, "SQLServerCallableStatement should be a wrapper for SQLServerStatement");
// Now unwrap the Callable to a statement and call a SQLServerStatement specific function and make sure it succeeds.
SQLServerStatement stmt2 = (SQLServerStatement) ((SQLServerCallableStatement) cs).unwrap(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerStatement"));
stmt2.setResponseBuffering("adaptive");
// now test the interface
isWrapper = ((SQLServerCallableStatement) cs).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerCallableStatement"));
assertEquals(isWrapper, true, "SQLServerCallableStatement should be a wrapper for ISQLServerCallableStatement");
// Now unwrap the Callable to a statement and call a SQLServerStatement specific function and make sure it succeeds.
ISQLServerPreparedStatement stmt4 = (ISQLServerPreparedStatement) ((SQLServerCallableStatement) cs).unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerPreparedStatement"));
stmt4.setResponseBuffering("adaptive");
if (isKatmaiServer())
stmt4.setDateTimeOffset(1, null);
// Try Unwrapping CallableStatement to a callableStatement
isWrapper = ((SQLServerCallableStatement) cs).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerCallableStatement"));
assertEquals(isWrapper, true, "SQLServerCallableStatement should be a wrapper for SQLServerCallableStatement");
// Now unwrap the Callable to a SQLServerCallableStatement and call a SQLServerStatement specific function and make sure it succeeds.
SQLServerCallableStatement stmt3 = (SQLServerCallableStatement) ((SQLServerCallableStatement) cs).unwrap(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerCallableStatement"));
stmt3.setResponseBuffering("adaptive");
if (isKatmaiServer()) {
stmt3.setDateTimeOffset(1, null);
}
if (null != stmt4) {
stmt4.close();
}
if (null != cs) {
cs.close();
}
} catch (UnsupportedOperationException e) {
assertEquals(System.getProperty("java.specification.version"), "1.5", "isWrapperFor should be supported in anything other than 1.5");
assertTrue(e.getMessage().equalsIgnoreCase("This operation is not supported."), "Wrong exception message");
} finally {
if (null != stmt) {
stmt.close();
}
if (null != con) {
con.close();
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class CallableStatementTest method getSetNullWithTypeVarchar.
/**
* test for setNull(index, varchar) to behave as setNull(index, nvarchar) when SendStringParametersAsUnicode is true
*
* @throws SQLException
*/
@Test
public void getSetNullWithTypeVarchar() throws SQLException {
String polishchar = "\u0143";
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
ds.setSendStringParametersAsUnicode(true);
String sql = "{? = call " + setNullProcedureName + " (?,?)}";
try (Connection connection = ds.getConnection();
SQLServerCallableStatement cs = (SQLServerCallableStatement) connection.prepareCall(sql);
SQLServerCallableStatement cs2 = (SQLServerCallableStatement) connection.prepareCall(sql)) {
cs.registerOutParameter(1, Types.INTEGER);
cs.setString(2, polishchar);
cs.setString(3, null);
cs.registerOutParameter(3, Types.VARCHAR);
cs.execute();
String expected = cs.getString(3);
cs2.registerOutParameter(1, Types.INTEGER);
cs2.setString(2, polishchar);
cs2.setNull(3, Types.VARCHAR);
cs2.registerOutParameter(3, Types.NVARCHAR);
cs2.execute();
String actual = cs2.getString(3);
assertEquals(expected, actual);
}
}
Aggregations