use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testImage.
/**
* Test text support
*
* @throws SQLException
*/
@Test
public void testImage() throws SQLException {
createTables("varbinary(max)");
createTVPS("varbinary(max)");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 10000; i++) buffer.append("a");
value = buffer.toString();
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.LONGVARBINARY);
tvp.addRow(value.getBytes());
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
Connection con = DriverManager.getConnection(connectionString);
ResultSet rs = con.createStatement().executeQuery("select * from " + table);
while (rs.next()) assertTrue(parseByte(rs.getBytes(1), value.getBytes()));
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testTVPImageStoredProcedure.
/**
* Image with StoredProcedure acts the same as varbinary(max)
*
* @throws SQLException
*/
@Test
public void testTVPImageStoredProcedure() throws SQLException {
createTables("image");
createTVPS("image");
createPreocedure();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 9000; i++) buffer.append("a");
value = buffer.toString();
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.LONGVARBINARY);
tvp.addRow(value.getBytes());
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()) assertTrue(parseByte(rs.getBytes(1), value.getBytes()));
if (null != P_C_statement) {
P_C_statement.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class DateAndTimeTypeTest method testQueryDateTVP.
/**
* Test query with date TVP
*/
@Test
public void testQueryDateTVP() throws SQLException {
SQLServerDataTable tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.DATE);
tvp.addRow(DATE_TO_TEST);
String sPrepStmt = "select * from dateandtime where my_date IN (select * from ?)";
pstmt = connection.prepareStatement(sPrepStmt);
((SQLServerPreparedStatement) pstmt).setStructured(1, "dateTVP", tvp);
rs = pstmt.executeQuery();
rs.next();
assertTrue(rs.getInt(1) == 42, "did not find correct timestamp");
rs.close();
pstmt.close();
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class DateAndTimeTypeTest method testQueryTimeTVP.
/**
* Test query with date TVP
*/
@Test
public void testQueryTimeTVP() throws SQLException {
SQLServerDataTable tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.TIME);
tvp.addRow(TIME_TO_TEST);
String sPrepStmt = "select * from dateandtime where my_time IN (select * from ?)";
pstmt = connection.prepareStatement(sPrepStmt);
((SQLServerPreparedStatement) pstmt).setStructured(1, "timeTVP", tvp);
rs = pstmt.executeQuery();
rs.next();
assertTrue(rs.getInt(1) == 42, "did not find correct timestamp");
rs.close();
pstmt.close();
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testNvarChar.
/**
* Test with nvarchar
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testNvarChar() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
String colValue = "س";
tvp.addRow(colValue);
pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + destTable + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
if (null != pstmt) {
pstmt.close();
}
rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTable);
while (rs.next()) {
assertEquals(rs.getString(1), colValue);
}
}
Aggregations