use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class DateAndTimeTypeTest method testQueryTimestampTVP.
/**
* Test query with date TVP
*/
@Test
public void testQueryTimestampTVP() throws SQLException {
SQLServerDataTable tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.TIMESTAMP);
tvp.addRow(TIMESTAMP_TO_TEST);
String sPrepStmt = "select * from dateandtime where my_timestamp IN (select * from ?)";
pstmt = connection.prepareStatement(sPrepStmt);
((SQLServerPreparedStatement) pstmt).setStructured(1, "timestampTVP", 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 testSmallInt.
/**
* Test with small int value
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testSmallInt() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
String[] numeric = createNumericValues();
tvp.addRow(Short.valueOf(numeric[2]));
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.getInt(1), numeric[2]);
// System.out.println(rs.getShort(1)); //does not work says cannot cast integer to short cause it is written as int
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testInt.
/**
* Test a previous failure regarding to numeric precision. Issue #211
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testInt() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
tvp.addRow(12);
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.getInt(1), 12);
assertEquals(rs.getString(1), "" + 12);
assertEquals(rs.getObject(1), 12);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testFloat.
/**
* Test with float value
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testFloat() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
String[] numeric = createNumericValues();
tvp.addRow(Float.parseFloat(numeric[1]));
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.getFloat(1), Float.parseFloat(numeric[1]));
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPWithSqlVariantTest method testBoolean.
/**
* Test with boolean value
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testBoolean() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.SQL_VARIANT);
String[] numeric = createNumericValues();
tvp.addRow(Boolean.parseBoolean(numeric[0]));
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.getBoolean(1), Boolean.parseBoolean(numeric[0]));
}
}
Aggregations