Search in sources :

Example 16 with SQLServerCallableStatement

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();
    }
}
Also used : SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 17 with SQLServerCallableStatement

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();
    }
}
Also used : SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 18 with SQLServerCallableStatement

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;
        }
    }
}
Also used : SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) SQLServerStatement(com.microsoft.sqlserver.jdbc.SQLServerStatement) IOException(java.io.IOException) SQLException(java.sql.SQLException) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 19 with SQLServerCallableStatement

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();
    }
}
Also used : SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) ResultSet(java.sql.ResultSet) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 20 with SQLServerCallableStatement

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();
    }
}
Also used : SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)51 SQLException (java.sql.SQLException)35 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)17 Test (org.junit.jupiter.api.Test)17 BigDecimal (java.math.BigDecimal)12 SQLServerDataTable (com.microsoft.sqlserver.jdbc.SQLServerDataTable)7 Connection (java.sql.Connection)5 ResultSet (java.sql.ResultSet)5 CallableStatement (java.sql.CallableStatement)4 Statement (java.sql.Statement)4 SQLServerStatement (com.microsoft.sqlserver.jdbc.SQLServerStatement)3 DisplayName (org.junit.jupiter.api.DisplayName)3 SQLServerDataSource (com.microsoft.sqlserver.jdbc.SQLServerDataSource)2 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)2 SQLServerResultSet (com.microsoft.sqlserver.jdbc.SQLServerResultSet)2 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)2 PreparedStatement (java.sql.PreparedStatement)2 Properties (java.util.Properties)2 ISQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.ISQLServerPreparedStatement)1 SQLServerCallableStatement42 (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement42)1