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();
}
}
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();
}
}
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);
}
}
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();
}
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();
}
}
Aggregations