use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class TVPSchemaTest method testTVPSchemaCallableInsertCommand.
/**
* Callable with InsertCommand
*
* @throws SQLException
* @throws IOException
*/
@Test
@DisplayName("TVPSchemaCallableInsertCommand()")
public void testTVPSchemaCallableInsertCommand() throws SQLException, IOException {
SQLServerCallableStatement P_C_stmt = (SQLServerCallableStatement) connection.prepareCall("INSERT INTO " + charTable + " select * from ? ;");
P_C_stmt.setStructured(1, tvpNameWithSchema, tvp);
P_C_stmt.executeUpdate();
rs = stmt.executeQuery("select * from " + charTable);
verify(rs);
if (null != P_C_stmt) {
P_C_stmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class TVPSchemaTest method testTVPSchemaCallableStatementStoredProcedure.
/**
* callableStatement with StoredProcedure
*
* @throws SQLException
*/
@Test
@DisplayName("TVPSchemaCallableStatementStoredProcedure()")
public void testTVPSchemaCallableStatementStoredProcedure() throws SQLException {
final String sql = "{call " + procedureName + "(?)}";
SQLServerCallableStatement P_C_statement = (SQLServerCallableStatement) connection.prepareCall(sql);
P_C_statement.setStructured(1, tvpNameWithSchema, tvp);
P_C_statement.execute();
rs = stmt.executeQuery("select * from " + charTable);
verify(rs);
if (null != P_C_statement) {
P_C_statement.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class TVPIssuesTest method testExceptionWithInvalidStoredProcedureName.
/**
* Test exception when invalid stored procedure name is used.
*
* @throws Exception
*/
@Test
public void testExceptionWithInvalidStoredProcedureName() throws Exception {
SQLServerStatement st = (SQLServerStatement) connection.createStatement();
ResultSet rs = st.executeQuery("select * from " + srcTable_varcharMax);
dropProcedure();
final String sql = "{call " + spName_varcharMax + "(?)}";
SQLServerCallableStatement Cstmt = (SQLServerCallableStatement) connection.prepareCall(sql);
try {
Cstmt.setObject(1, rs);
throw new Exception("Expected Exception for invalied stored procedure name is not thrown.");
} catch (Exception e) {
if (e instanceof SQLException) {
assertTrue(e.getMessage().contains("Could not find stored procedure"), "Invalid Error Message.");
} else {
throw e;
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class TVPResultSetCursorTest method testSelectMethodSetToCursorWithSP.
/**
* Test a previous failure when setting SelectMethod to cursor and using the same connection to create TVP, SP and result set.
*
* @throws SQLException
*/
@Test
public void testSelectMethodSetToCursorWithSP() throws SQLException {
Properties info = new Properties();
info.setProperty("SelectMethod", "cursor");
conn = DriverManager.getConnection(connectionString, info);
stmt = conn.createStatement();
dropProcedure();
dropTVPS();
dropTables();
createTVPS();
createTables();
createPreocedure();
populateSourceTable();
ResultSet rs = conn.createStatement().executeQuery("select * from " + srcTable);
final String sql = "{call " + procedureName + "(?)}";
SQLServerCallableStatement pstmt = (SQLServerCallableStatement) conn.prepareCall(sql);
pstmt.setStructured(1, tvpName, rs);
try {
pstmt.execute();
verifyDestinationTableData(expectedBigDecimals.length);
} finally {
if (null != pstmt) {
pstmt.close();
}
if (null != rs) {
rs.close();
}
dropProcedure();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testTVPLongNVarcharStoredProcedure.
/**
* LongNVarchar with StoredProcedure
*
* @throws SQLException
*/
@Test
public void testTVPLongNVarcharStoredProcedure() throws SQLException {
createTables("nvarchar(max)");
createTVPS("nvarchar(max)");
createPreocedure();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 8001; i++) buffer.append("سس");
value = buffer.toString();
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.LONGNVARCHAR);
tvp.addRow(buffer.toString());
final String sql = "{call " + procedureName + "(?)}";
SQLServerCallableStatement P_C_statement = (SQLServerCallableStatement) connection.prepareCall(sql);
P_C_statement.setStructured(1, tvpName, tvp);
P_C_statement.execute();
rs = stmt.executeQuery("select * from " + table);
while (rs.next()) assertEquals(rs.getString(1), value);
if (null != P_C_statement) {
P_C_statement.close();
}
}
Aggregations