Search in sources :

Example 21 with SQLServerCallableStatement

use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.

the class TVPTypesTest method testTVPNTextStoredProcedure.

/**
 * Text with StoredProcedure
 *
 * @throws SQLException
 */
@Test
public void testTVPNTextStoredProcedure() throws SQLException {
    createTables("ntext");
    createTVPS("ntext");
    createPreocedure();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 9000; i++) buffer.append("س");
    value = buffer.toString();
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", java.sql.Types.LONGNVARCHAR);
    tvp.addRow(value);
    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)

Example 22 with SQLServerCallableStatement

use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.

the class TVPTypesTest method testTVPLongVarcharStoredProcedure.

/**
 * LongVarchar with StoredProcedure
 *
 * @throws SQLException
 */
@Test
public void testTVPLongVarcharStoredProcedure() throws SQLException {
    createTables("varchar(max)");
    createTVPS("varchar(max)");
    createPreocedure();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 8001; i++) buffer.append("a");
    value = buffer.toString();
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", java.sql.Types.LONGVARCHAR);
    tvp.addRow(value);
    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)

Example 23 with SQLServerCallableStatement

use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.

the class Wrapper42Test method CallableStatement42Test.

/**
 * Tests creation of SQLServerCallableStatement42 object
 *
 * @throws SQLException
 */
@Test
public void CallableStatement42Test() throws SQLException {
    String sql = "SELECT SUSER_SNAME()";
    CallableStatement cstmt = connection.prepareCall(sql);
    if (1.8d <= javaVersion && 4 == major && 2 == minor) {
        assertTrue(cstmt instanceof SQLServerCallableStatement42);
    } else {
        assertTrue(cstmt instanceof SQLServerCallableStatement);
    }
}
Also used : SQLServerCallableStatement42(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement42) SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) CallableStatement(java.sql.CallableStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 24 with SQLServerCallableStatement

use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.

the class TVPAllTypes method testTVPStoredProcedureResultSet.

private void testTVPStoredProcedureResultSet(boolean setSelectMethod, Integer resultSetType, Integer resultSetConcurrency) throws SQLException {
    setupVariation();
    Connection connnection = null;
    if (setSelectMethod) {
        connnection = DriverManager.getConnection(connectionString + ";selectMethod=cursor;");
    } else {
        connnection = DriverManager.getConnection(connectionString);
    }
    Statement stmtement = null;
    if (null != resultSetType || null != resultSetConcurrency) {
        stmtement = connnection.createStatement(resultSetType, resultSetConcurrency);
    } else {
        stmtement = connnection.createStatement();
    }
    ResultSet rs = stmtement.executeQuery("select * from " + tableSrc.getEscapedTableName());
    String sql = "{call " + procedureName + "(?)}";
    SQLServerCallableStatement Cstmt = (SQLServerCallableStatement) connnection.prepareCall(sql);
    Cstmt.setStructured(1, tvpName, rs);
    Cstmt.execute();
    ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connectionString), tableSrc, tableDest);
    terminateVariation();
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) Statement(java.sql.Statement) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Connection(java.sql.Connection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) ResultSet(java.sql.ResultSet)

Example 25 with SQLServerCallableStatement

use of com.microsoft.sqlserver.jdbc.SQLServerCallableStatement in project mssql-jdbc by Microsoft.

the class TVPResultSetCursorTest method testInvalidStoredProcedureName.

/**
 * Test exception when giving invalid stored procedure name
 *
 * @throws SQLException
 */
@Test
public void testInvalidStoredProcedureName() 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 invalid" + procedureName + "(?)}";
    SQLServerCallableStatement pstmt = (SQLServerCallableStatement) conn.prepareCall(sql);
    pstmt.setStructured(1, tvpName, rs);
    try {
        pstmt.execute();
    } catch (SQLException e) {
        if (!e.getMessage().contains("Could not find stored procedure")) {
            throw e;
        }
    } finally {
        if (null != pstmt) {
            pstmt.close();
        }
        if (null != rs) {
            rs.close();
        }
        dropProcedure();
    }
}
Also used : SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Properties(java.util.Properties) 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