use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPAllTypes method testTVPDataTable.
/**
* Test TVP with DataTable
*
* @throws SQLException
*/
@Test
public void testTVPDataTable() throws SQLException {
setupVariation();
SQLServerDataTable dt = new SQLServerDataTable();
int numberOfColumns = tableDest.getColumns().size();
Object[] values = new Object[numberOfColumns];
for (int i = 0; i < numberOfColumns; i++) {
SqlType sqlType = tableDest.getColumns().get(i).getSqlType();
dt.addColumnMetadata(tableDest.getColumnName(i), sqlType.getJdbctype().getVendorTypeNumber());
values[i] = sqlType.createdata();
}
int numberOfRows = 10;
for (int i = 0; i < numberOfRows; i++) {
dt.addRow(values);
}
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + tableDest.getEscapedTableName() + " select * from ? ;");
pstmt.setStructured(1, tvpName, dt);
pstmt.execute();
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPNumericTest method testNumericPresicionIssue211.
/**
* Test a previous failure regarding to numeric precision. Issue #211
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testNumericPresicionIssue211() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.NUMERIC);
tvp.addRow(12.12);
tvp.addRow(1.123);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + charTable + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testDateTime.
/**
* Test a datetime support
*
* @throws SQLException
*/
@Test
public void testDateTime() throws SQLException {
createTables("datetime");
createTVPS("datetime");
java.sql.Timestamp value = java.sql.Timestamp.valueOf("2007-09-23 10:10:10.123");
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", microsoft.sql.Types.DATETIME);
tvp.addRow(value);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
rs = conn.createStatement().executeQuery("select * from " + table);
while (rs.next()) {
assertEquals(((SQLServerResultSet) rs).getDateTime(1), value);
}
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testXML.
/**
* Test xml support
*
* @throws SQLException
*/
@Test
public void testXML() throws SQLException {
createTables("xml");
createTVPS("xml");
value = "<vx53_e>Variable E</vx53_e>" + "<vx53_f>Variable F</vx53_f>" + "<doc>API<!-- comments --></doc>" + "<doc>The following are Japanese chars.</doc>" + "<doc> Some UTF-8 encoded characters: �������</doc>";
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.SQLXML);
tvp.addRow(value);
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()) assertEquals(rs.getString(1), value);
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.
the class TVPTypesTest method testTVPXMLStoredProcedure.
/**
* XML with StoredProcedure
*
* @throws SQLException
*/
@Test
public void testTVPXMLStoredProcedure() throws SQLException {
createTables("xml");
createTVPS("xml");
createPreocedure();
value = "<vx53_e>Variable E</vx53_e>" + "<vx53_f>Variable F</vx53_f>" + "<doc>API<!-- comments --></doc>" + "<doc>The following are Japanese chars.</doc>" + "<doc> Some UTF-8 encoded characters: �������</doc>";
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.SQLXML);
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();
}
}
Aggregations